|
| 1 | +#include <stdio.h> |
| 2 | +#include <vector> |
| 3 | +#include <queue> |
| 4 | +#include <algorithm> |
| 5 | + |
| 6 | +using namespace std; |
| 7 | + |
| 8 | +int const N = 1e5 + 1; |
| 9 | +int n, m, k, res; |
| 10 | +long long cost[N]; |
| 11 | +bool vis[N]; |
| 12 | +vector<vector<pair<int, int> > > g; |
| 13 | +priority_queue<pair<pair<long long, int>, bool> > q; |
| 14 | + |
| 15 | +void Dijkstra(int src) { |
| 16 | + fill(cost, cost + N, 1e18); |
| 17 | + q.push(make_pair(make_pair(0, src), false)); |
| 18 | + cost[src] = 0; |
| 19 | + |
| 20 | + while(!q.empty()) { |
| 21 | + int v = q.top().first.second; |
| 22 | + long long c = -q.top().first.first; |
| 23 | + bool train = q.top().second; |
| 24 | + q.pop(); |
| 25 | + |
| 26 | + if(cost[v] <= c && train) { |
| 27 | + ++res; |
| 28 | + continue; |
| 29 | + } else if(cost[v] > c && train) |
| 30 | + cost[v] = c; |
| 31 | + |
| 32 | + if(vis[v]) |
| 33 | + continue; |
| 34 | + vis[v] = true; |
| 35 | + |
| 36 | + for(int i = 0, u; i < (int)g[v].size(); ++i) { |
| 37 | + u = g[v][i].first; |
| 38 | + if(1LL * c + g[v][i].second < cost[u]) { |
| 39 | + cost[u] = 1LL * c + g[v][i].second; |
| 40 | + q.push(make_pair(make_pair(-cost[u], u), false)); |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +int main() { |
| 47 | + scanf("%d %d %d", &n, &m, &k); |
| 48 | + g.resize(n); |
| 49 | + |
| 50 | + for(int i = 0, a, b, c; i < m; ++i) { |
| 51 | + scanf("%d %d %d", &a, &b, &c); |
| 52 | + --a, --b; |
| 53 | + g[a].push_back(make_pair(b, c)); |
| 54 | + g[b].push_back(make_pair(a, c)); |
| 55 | + } |
| 56 | + |
| 57 | + for(int i = 0, a, c; i < k; ++i) { |
| 58 | + scanf("%d %d", &a, &c); |
| 59 | + --a; |
| 60 | + q.push(make_pair(make_pair(-c, a), true)); |
| 61 | + } |
| 62 | + |
| 63 | + Dijkstra(0); |
| 64 | + |
| 65 | + printf("%d\n", res); |
| 66 | + |
| 67 | + return 0; |
| 68 | +} |
| 69 | + |
0 commit comments