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 mroads 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.
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 ≤ n; ui ≠ 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 a single integer representing the maximum number of the train routes which can be closed.
5 5 3 1 2 1 2 3 2 1 3 3 3 4 4 1 5 5 3 5 4 5 5 5
2
2 2 3 1 2 2 2 1 3 2 1 2 2 2 3
2
#include
#include
#include
#include
#include
using namespace std; #define maxn 100010 #define INF (0x7fffffffffffffff-((1<<31)-1)) typedef long long ll; struct node{ int v; int vis; int w; }; int n,m,k; int head[maxn]; node edge[maxn*8]; int next[maxn*8]; ll dp[maxn]; int vis[maxn]; int fa[maxn]; int ans; int d; typedef pair
pii; priority_queue
,greater
>q; void add(int u,int v,int w,int vis) { edge[d].v=v; edge[d].w=w; edge[d].vis=vis; next[d]=head[u]; head[u]=d++; } void spfa() { memset(vis,0,sizeof(vis)); int i; for(i=1;i<=n;i++)dp[i]=INF; memset(fa,-1,sizeof(fa)); dp[1]=0; q.push(make_pair(0,1)); while(!q.empty()) { pii ff=q.top();q.pop(); int f=ff.second; if(vis[f])continue; vis[f]=1; for(i=head[f];i!=-1;i=next[i]){ int v=edge[i].v; int w=edge[i].w; int vi=edge[i].vis; if(dp[v]>dp[f]+w){ dp[v]=dp[f]+w; if(fa[v]!=-1&&edge[fa[v]].vis)ans--; fa[v]=i; if(vi)ans++; q.push(make_pair(dp[v],v)); } else if(dp[v]==dp[f]+w&&edge[fa[v]].vis&&!vi){ fa[v]=i; ans--; } } } } int main() { while(scanf("%d%d%d",&n,&m,&k)!=EOF) { int u,v,w,i; memset(head,-1,sizeof(head)); d=0; for(i=0;i