B. 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 m roads connecting the cities. One can go from city u i to v i (and vise versa) using the i -th road, the length of this road is x i . 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 s i (and vise versa), the length of this route is y i .
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 ≤ 10 5 ; 1 ≤ m ≤ 3·10 5 ; 1 ≤ k ≤ 10 5 ) .
Each of the next m lines contains three integers u i , v i , x i (1 ≤ u i , v i ≤ n ; u i ≠ v i ; 1 ≤ x i ≤ 10 9 ) .
Each of the next k lines contains two integers s i and y i (2 ≤ s i ≤ n ; 1 ≤ y i ≤ 10 9 ) .
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.
题意:
有n个城市 从1到n,其中1为首都。每个城市之间有很多条道路,1到其他城市之间有一些铁轨。现在要在最短路不变的情况下,删掉尽量多的铁轨。输出删掉的铁轨数。
真·从早wa到晚,最后换了一种写法= =。。。就很难过
一开始的想法是把所有边都加进去,然后dijk,但在更新dis值得时候多增加一个数组rout[u]记录当前这个点的最短路径上有多少条铁轨。
如果dis[son]>dis[father]+eg[i].w 那么就根据i是不是铁轨更新这个rout
如果dis[son]==dis[father]+eg[i].w 那么就从看是原先rout[son]小还是通过边i 从father转移过来更小,依此来更新rout[son],
同时每次更新都要记录这个点的最短路是由哪个边转移过来的。
最后统计所有点所记录的边,如果是铁轨边那么就tot++;
tot是保留下来的铁轨数
ans就是k-tot;
自我感觉好像没得毛病哈。。。。。
测一些小数据基本都能过,但一旦大了 ans就会偏小。。。。
现在都还没想通。。。
代码贴出来有大佬愿意看的话麻烦告诉我猫饼在哪儿QAQ
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
struct Pair{
int D,V;
Pair(long long d,int v){
D=d,V=v;
}
friend bool operator< (c