#include<bits/stdc++.h> using namespace std; int n,m,q; int kol[200010]; set<pair<int,int>> graph[200010]; void dfs(int idx, int par, long long dist, long long max_dist, int colour){ kol[idx] = colour; for(auto v : graph[idx]){ if(v.first == par) continue; if(dist + v.second <= max_dist){ dfs(v.first,idx,dist + v.second,max_dist,colour); } } } int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> m >> q; int a,b,d; for(int i = 0; i < m; i++){ cin >> a >> b >> d; graph[a].insert({b,d}); graph[b].insert({a,d}); } int t,k; long long z; while(q--){ cin >> t; if(t == 1){ cin >> a >> b >> d; graph[a].insert({b,d}); graph[b].insert({a,d}); } if(t == 2){ cin >> a >> b; graph[a].erase(graph[a].upper_bound({b,0})); graph[b].erase(graph[b].upper_bound({a,0})); } if(t == 3){ cin >> a >> z >> k; dfs(a,0,0,z,k); } if(t == 4){ cin >> a; cout << kol[a] << "\n"; } } return 0; }
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 52 53 54 55 56 | #include<bits/stdc++.h> using namespace std; int n,m,q; int kol[200010]; set<pair<int,int>> graph[200010]; void dfs(int idx, int par, long long dist, long long max_dist, int colour){ kol[idx] = colour; for(auto v : graph[idx]){ if(v.first == par) continue; if(dist + v.second <= max_dist){ dfs(v.first,idx,dist + v.second,max_dist,colour); } } } int main(){ cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> n >> m >> q; int a,b,d; for(int i = 0; i < m; i++){ cin >> a >> b >> d; graph[a].insert({b,d}); graph[b].insert({a,d}); } int t,k; long long z; while(q--){ cin >> t; if(t == 1){ cin >> a >> b >> d; graph[a].insert({b,d}); graph[b].insert({a,d}); } if(t == 2){ cin >> a >> b; graph[a].erase(graph[a].upper_bound({b,0})); graph[b].erase(graph[b].upper_bound({a,0})); } if(t == 3){ cin >> a >> z >> k; dfs(a,0,0,z,k); } if(t == 4){ cin >> a; cout << kol[a] << "\n"; } } return 0; } |