Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city ui to vi (and vise versa) using the i-th road, the length of this road is xi. Finally, there are k train routes in the country. One can use the i-th train route to go from capital of the country to city si (and vise versa), the length of this route is yi.

Jzzhu doesn't want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn't change.

Input

The first line contains three integers n, m, k (2 ≤ n ≤ 105; 1 ≤ m ≤ 3·105; 1 ≤ k ≤ 105).

Each of the next m lines contains three integers ui, vi, xi (1 ≤ ui, vi ≤ nui ≠ vi; 1 ≤ xi ≤ 109).

Each of the next k lines contains two integers si and yi (2 ≤ si ≤ n; 1 ≤ yi ≤ 109).

It is guaranteed that there is at least one way from every city to the capital. Note, that there can be multiple roads between two cities. Also, there can be multiple routes going to the same city from the capital.

Output

Output a single integer representing the maximum number of the train routes which can be closed.

Examples
input

Copy
5 5 3
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
3 5
4 5
5 5
output

Copy
2
input

Copy
2 2 3
1 2 2
2 1 3
2 1
2 2
2 3
output

Copy
2

一次spfa
考虑对每个点,每次被更新时,有两种情况,铁路和公路,被铁路更新标记为1(被认为不能删),被公路更新就标记回0.
另一方面,当dis[v]==dis[u]+w时,如果已被标记为1,那还需要重新标记
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define scanf1(x) scanf("%d", &x)
#define scanf2(x, y) scanf("%d%d", &x, &y)
#define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define bug printf("***********\n");
#define mp make_pair
#define pb push_back
const int N =1e6;
const int M=;
// name*******************************
struct edge
{
int to,nxt;
ll w;
} e[N];
int tot=;
int fst[N];
ll dis[N];
int ins[N];
int vis[N];
int pos[N];
priority_queue<int>que;
int sum=;
int n,m,k;
// function******************************
void add(int u,int v,int w)
{
e[++tot].to=v;
e[tot].nxt=fst[u];
fst[u]=tot;
e[tot].w=w;
}
void spfa()
{
For(i,,n)dis[i]=INF;
que.push();
ins[]=;
dis[]=;
while(!que.empty())
{
int u=que.top();
que.pop();
ins[u]=;
for(int p=fst[u]; p; p=e[p].nxt)
{
int v=e[p].to;
ll w=e[p].w;
if(dis[v]==dis[u]+w&&pos[v])
pos[v]=vis[p];
if(dis[v]>dis[u]+w)
{
dis[v]=dis[u]+w;
pos[v]=vis[p];
if(!ins[v])
{
ins[v]=;
que.push(v);
}
}
}
}
} //***************************************
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// freopen("test.txt", "r", stdin);
// freopen("outout.txt","w",stdout);
scanf("%d%d%d",&n,&m,&k);
For(i,,m)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
For(i,,k)
{
int x,y;
scanf("%d%d",&x,&y);
add(,x,y);
vis[tot]=;
}
spfa();
For(i,,n)
sum+=pos[i];
cout<<k-sum; return ;
}

D. Jzzhu and Cities的更多相关文章

  1. CF449B Jzzhu and Cities (最短路)

    CF449B CF450D http://codeforces.com/contest/450/problem/D http://codeforces.com/contest/449/problem/ ...

  2. Codeforces Round #257 (Div. 2) D题:Jzzhu and Cities 删特殊边的最短路

    D. Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces 449 B. Jzzhu and Cities

    堆优化dijkstra,假设哪条铁路能够被更新,就把相应铁路删除. B. Jzzhu and Cities time limit per test 2 seconds memory limit per ...

  4. Codeforces C. Jzzhu and Cities(dijkstra最短路)

    题目描述: Jzzhu and Cities time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  5. CF449B Jzzhu and Cities 迪杰斯特拉最短路算法

    CF449B Jzzhu and Cities 其实这一道题并不是很难,只是一个最短路而已,请继续看我的题解吧~(^▽^) AC代码: #include<bits/stdc++.h> #d ...

  6. Codeforces 450D:Jzzhu and Cities(最短路,dijkstra)

    D. Jzzhu and Cities time limit per test: 2 seconds memory limit per test: 256 megabytes input: stand ...

  7. codeforces 449B Jzzhu and Cities (Dij+堆优化)

    输入一个无向图<V,E>    V<=1e5, E<=3e5 现在另外给k条边(u=1,v=s[k],w=y[k]) 问在不影响从结点1出发到所有结点的最短路的前提下,最多可以 ...

  8. Codeforces Round #257(Div.2) D Jzzhu and Cities --SPFA

    题意:n个城市,中间有m条道路(双向),再给出k条铁路,铁路直接从点1到点v,现在要拆掉一些铁路,在保证不影响每个点的最短距离(距离1)不变的情况下,问最多能删除多少条铁路 分析:先求一次最短路,铁路 ...

  9. Codeforces 450D Jzzhu and Cities [heap优化dij]

    #include<bits/stdc++.h> #define MAXN 100050 #define MAXM 900000 using namespace std; struct st ...

随机推荐

  1. HDU4162(最小循环表示)

    Shape Number Time Limit: 24000/12000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  2. 在pycharm中进行ORM操作

    打开manage.py, 复制 import..... if.......os.....  导入django,开启django, 导入app中的models  orm操作 import os if _ ...

  3. MySQL两种存储引擎: MyISAM和InnoDB

    MySQL两种存储引擎: MyISAM和InnoDB 简单总结   MyISAM是MySQL的默认数据库引擎(5.5版之前),由早期的ISAM(Indexed Sequential Access Me ...

  4. Stylus基本使用

    介绍 在学习一个 Vue.js 项目的过程中,注意到源码中样式的部分并没有用熟悉的 .css 样式文件,而是发现了代码长得和 CSS 相像的 .styl 文件.这个 .styl 以前没见过啊,你是谁? ...

  5. SQL2008R2数据库日志太大收缩方法

    1.登陆项目平台数据库服务器.双击SQL Server Management Studio打开数据库管理.登陆数据库 2.如下图,打开数据库属性窗口 3.如下图,更改数据库恢复模式 4.如下图,收缩数 ...

  6. 安卓测试【一】android sdk环境变量配置

    移动应用自动化测试的配置,先于官网下载Android SDK,然后配置环境变量. 配置android sdk环境变量 1.  新建ANDROID_HOME环境变量,变量值为SDK解压的路径 2. 追加 ...

  7. [iOS] UICollectionView实现图片水平滚动

    最新更新: 简单封装了一下代码,参考新文章:UICollectionView实现图片水平滚动 先简单看一下效果: 新博客:http://wossoneri.github.io 准备数据 首先先加入一些 ...

  8. [WPF 基础知识系列] —— 绑定中的数据校验Vaildation

    前言: 只要是有表单存在,那么就有可能有对数据的校验需求.如:判断是否为整数.判断电子邮件格式等等. WPF采用一种全新的方式 - Binding,来实现前台显示与后台数据进行交互,当然数据校验方式也 ...

  9. Python图像识别(聚类)

    # -*- coding: utf-8 -*- """ Created on Fri Sep 21 15:37:26 2018 @author: zhen "& ...

  10. Oracle EBS OM 创建订单

    DECLARE l_header_rec OE_ORDER_PUB.Header_Rec_Type; l_line_tbl OE_ORDER_PUB.Line_Tbl_Type; l_action_r ...