博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
D. Jzzhu and Cities
阅读量:5121 次
发布时间:2019-06-13

本文共 3731 字,大约阅读时间需要 12 分钟。

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 
using namespace std;typedef long long ll;#define inf 2147483647const ll INF = 0x3f3f3f3f3f3f3f3fll;#define ri register inttemplate
inline T min(T a, T b, T c){ return min(min(a, b), c);}template
inline T max(T a, T b, T c){ return max(max(a, b), c);}template
inline T min(T a, T b, T c, T d){ return min(min(a, b), min(c, d));}template
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_backconst int N =1e6;const int M=200005;// name*******************************struct edge{ int to,nxt; ll w;} e[N];int tot=1;int fst[N];ll dis[N];int ins[N];int vis[N];int pos[N];priority_queue
que;int sum=0;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,1,n)dis[i]=INF; que.push(1); ins[1]=1; dis[1]=0; while(!que.empty()) { int u=que.top(); que.pop(); ins[u]=0; 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]=1; 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,1,m) { int u,v,w; scanf("%d%d%d",&u,&v,&w); add(u,v,w); add(v,u,w); } For(i,1,k) { int x,y; scanf("%d%d",&x,&y); add(1,x,y); vis[tot]=1; } spfa(); For(i,1,n) sum+=pos[i]; cout<

 

 

转载于:https://www.cnblogs.com/planche/p/8903086.html

你可能感兴趣的文章
【架构】Linux的架构(architecture)
查看>>
从解决Cocos2dx-2.x arm64 Crash 来看C的奇技淫巧
查看>>
ASM 图解
查看>>
石子合并(一)
查看>>
Hibernate批量删除的两种方式
查看>>
Maven入门指南③:坐标和依赖
查看>>
MVC 校验
查看>>
Atheros AR9485 ubuntu 10.04 驱动安装及networking disable问题解决
查看>>
linux开发缩写
查看>>
java基础第十六篇之多线程
查看>>
3527: [Zjoi2014]力 - BZOJ
查看>>
17 , CSS 区块、浮动、定位、溢出、滚动条
查看>>
屏蔽元素默认样式中的边距
查看>>
bzoj1084(SCOI2005)最大子矩阵
查看>>
BZOJ2563 阿狸和桃子的游戏
查看>>
3. Scheme约束XML
查看>>
Tensorflow一些常用基本概念与函数(四)
查看>>
LOJ#6044. 「雅礼集训 2017 Day8」共(Prufer序列)
查看>>
状态栏的颜色设置
查看>>
left join 右表数据不唯一的情况解决方法
查看>>