Codeforces Round #257 (Div. 2)D(最短路Dijkstra+堆优化)

来源:互联网 发布:r软件下载 编辑:程序博客网 时间:2024/06/08 18:24
D. Jzzhu and Cities
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

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.

Sample test(s)
input
5 5 31 2 12 3 21 3 33 4 41 5 53 54 55 5
output
2
input
2 2 31 2 22 1 32 12 22 3
output
2

题意:给了n个点,m条边,k条专线(起点一定为1),都是双向的,要求的是最多可以删掉多少条专线,使得1结点到任何其它节点的最短路长度不变

思路:裸的最短路,只是在跑最短路的时候记录一下即可,如果 i 可以被更新,那么判断更新 i 的边是否为专线,是就+1,然后判断原来直达 i 的边是否为专线,是就-1,还有

            一个要判断的地方是,当前到 i 最短路的值和 i 以前的一样,那么就判断以前直达 i 的边是否为专线,且现在的边不是专线,不然专线替换专线没意义,是就将之替

            换为当前的边,同时答案-1,最后输出答案即可,我先用spfa写在第45组超时了,之后改成迪杰斯特拉堆优化就过了

0 0
原创粉丝点击