-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCF449B.cpp
More file actions
51 lines (51 loc) · 1.15 KB
/
Copy pathCF449B.cpp
File metadata and controls
51 lines (51 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
#include <queue>
using namespace std;
int n, m, k, ans;
struct EDGE {
int to;
long long dis;
};
vector< EDGE > v[100005];
int wp[100005], wp2[100005];
long long tmpx, tmpy, tmpz, dis[100005];
queue< int > qu;
void SPFA() {
register int nown, to;
while(!qu.empty()) {
nown= qu.front(), qu.pop(), wp[nown]= 0;
for(int i= 0; i < (int)v[nown].size(); i++) {
to= v[nown][i].to;
if(dis[to] == dis[nown] + v[nown][i].dis) wp2[to]= 0;
if(dis[to] > dis[nown] + v[nown][i].dis) {
dis[to]= dis[nown] + v[nown][i].dis, wp2[to]= 0;
if(!wp[to]) wp[to]= 1, qu.push(to);
}
}
}
return;
}
int main() {
cin >> n >> m >> k;
for(int i= 1; i <= m; i++) {
cin >> tmpx >> tmpy >> tmpz;
v[tmpx].push_back(EDGE{tmpy, tmpz}), v[tmpy].push_back(EDGE{tmpx, tmpz});
}
memset(dis, 0x3f, sizeof(dis)), dis[1]= 0;
wp[1]= 0, qu.push(1);
for(int i= 1; i <= k; i++) {
cin >> tmpx >> tmpy;
if(dis[tmpx] > tmpy) {
if(!wp[tmpx]) wp[tmpx]= 1, qu.push(tmpx);
dis[tmpx]= tmpy, wp2[tmpx]= 1;
}
}
SPFA();
ans= k;
for(int i= 1; i <= n; i++) ans-= wp2[i];
cout << ans << endl;
return 0;
}