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?≤?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
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
input
2 2 31 2 22 1 32 12 22 3
output
思路:這題只要引入一個最短路條數,然后再遍歷火車線,如果最短路與火車線長度相等,此時如果最短路條數是1的話,那說明這個最短路就是火車線,不能去掉,如果最短路條數大于1條,說明除了這條火車線外還有別的跟他同樣短的路,可以去掉;如果火車線長度比最短路長的話,顯然可以去掉。
這題剛開始看確實挺蛋疼的,比賽的時候也沒啥想法。好久不做圖論方面的了,所以有點不會了。
剛才敲spfa還重新看了下這算法才會手敲,確實有點生了。
剛開始queue沒過,T了。然后改成優(yōu)先隊列就過了。呵呵。沒明白。不是dijkstra才得用優(yōu)先隊列么,這題為什么也要用。后面想想,應該是先后問題T了。
#include#include #include #include#include
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com