#include <bits/stdc++.h> using namespace std; typedef long long ll; map<pair<ll,ll>, ll> wart; set<pair<ll,ll> > sas[200001]; ll kolor[200001]; void DFS(ll v, ll father, ll dist, ll z, ll k){ if (dist > z) return; kolor[v] = k; for (auto j : sas[v]){ ll u = j.first; ll c = j.second; if (u == father) continue; DFS(u,v,dist+c,z,k); } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n,m,q; cin>>n>>m>>q; while (m--){ ll a,b,c; cin>>a>>b>>c; if (a > b) swap(a,b); wart[{a,b}] = c; sas[a].insert({b,c}); sas[b].insert({a,c}); } while (q--){ ll type; cin>>type; if (type == 1){ ll a,b,d; cin>>a>>b>>d; if (a > b) swap(a,b); wart[{a,b}] = d; sas[a].insert({b,d}); sas[b].insert({a,d}); } if (type == 2){ ll a,b; cin>>a>>b; if (a > b) swap(a,b); sas[a].erase({b,wart[{a,b}]}); sas[b].erase({a,wart[{a,b}]}); } if (type == 3){ ll v,z,k; cin>>v>>z>>k; DFS(v,-1,0,z,k); } if (type == 4){ ll v; cin>>v; cout<<kolor[v]<<"\n"; } } }
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 57 58 59 60 | #include <bits/stdc++.h> using namespace std; typedef long long ll; map<pair<ll,ll>, ll> wart; set<pair<ll,ll> > sas[200001]; ll kolor[200001]; void DFS(ll v, ll father, ll dist, ll z, ll k){ if (dist > z) return; kolor[v] = k; for (auto j : sas[v]){ ll u = j.first; ll c = j.second; if (u == father) continue; DFS(u,v,dist+c,z,k); } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n,m,q; cin>>n>>m>>q; while (m--){ ll a,b,c; cin>>a>>b>>c; if (a > b) swap(a,b); wart[{a,b}] = c; sas[a].insert({b,c}); sas[b].insert({a,c}); } while (q--){ ll type; cin>>type; if (type == 1){ ll a,b,d; cin>>a>>b>>d; if (a > b) swap(a,b); wart[{a,b}] = d; sas[a].insert({b,d}); sas[b].insert({a,d}); } if (type == 2){ ll a,b; cin>>a>>b; if (a > b) swap(a,b); sas[a].erase({b,wart[{a,b}]}); sas[b].erase({a,wart[{a,b}]}); } if (type == 3){ ll v,z,k; cin>>v>>z>>k; DFS(v,-1,0,z,k); } if (type == 4){ ll v; cin>>v; cout<<kolor[v]<<"\n"; } } } |