dijkstra+堆。。。如果一条铁路可以被更新,就删除那条铁路。
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.
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<iostream> #include<cstring> #include<cstdio> using namespace std; #define prt(k) cout<<#k"="<<k<<" "; #define ll long long #define inf 0x3f3f3f3f #define N 300333 #include<vector> #define pb push_back #define mp make_pair int n,m,k; int d[N]; #include<queue> bool vis[N]; vector<int> to[N],dist[N]; int main() { scanf("%d%d%d",&n,&m,&k); for(int i=0;i<m;i++) { int u,v,w; scanf("%d%d%d",&u,&v,&w); to[u].pb(v) ; dist[u].pb(w); to[v].pb(u) ; dist[v].pb(w); } priority_queue<pair<ll,int> > q; q.push(mp(0,1)); for(int i=0;i<k;i++) { int s,y; scanf("%d%d",&s,&y); q.push(mp(-y,s-n)); } int ans=0; memset(vis,0,sizeof(vis)); while(!q.empty()) { pair<ll,int> t=q.top(); q.pop(); int u=t.second,w=t.first; if(u<1) { u+=n; if(vis[u]) ++ans; } if(vis[u]) continue; vis[u]=1; for(int i=0;i<to[u].size();i++) q.push(mp(w-dist[u][i],to[u][i])); } cout<<ans<<endl; }