CF449B T了第五组
#include<iostream>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;
struct aa {
int v;
int val;
const bool operator < (const aa &r) const {return val >r.val;}
};
int zdl[100010] = {};
bool vis[100010] = {};
vector<aa> ve[100010] = {};
bool lian[100010] = {};
int last[100010] = {};
priority_queue<pair<int, int> > q;
int ans = 0;
int n = 0;
int m = 0;
int k = 0;
void dijistra() {
memset(zdl,0x3f3f3f3f,sizeof(zdl));
priority_queue<aa> q;
zdl[1] = 0;
q.push({1, 0});
while(!q.empty()) {
aa nn = q.top();
q.pop();
vis[nn.v] = true;
for (auto vv : ve[nn.v]) {
if(zdl[vv.v] >= nn.val + vv.val) {
if(lian[vv.v] && nn.v != 1) {
ans++;
lian[vv.v] = false;
}
zdl[vv.v] = nn.val + vv.val;
if(!vis[vv.v]) {
q.push({vv.v, zdl[vv.v]});
}
}
}
}
}
int main() {
// freopen("test.in", "r", stdin);
// freopen("test.out", "w", stdout);
cin >> n >> m >> k;
memset(last,0x3f3f3f3f,sizeof(last));
for (int i = 0; i < m; ++i) {
int u = 0;
int v = 0;
int z = 0;
cin >> u >> v >> z;
if(u == 1) {
last[v] = min(last[v], z);
}
if(v == 1){
last[u] = min(last[u], z);
}
ve[u].push_back({v, z});
ve[v].push_back({u, z});
}
for (int i = 0; i < k; ++i) {
int s = 0;
int z = 0;
cin >> s >> z;
if(lian[s] || last[s] <= z) {
ans++;
}
if (last[s] > z) {
lian[s] = true;
last[s] = z;
ve[1].push_back({s, z});
ve[s].push_back({1, z});
}
}
dijistra();
cout << ans;
return 0;
}