#include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=2e5+7; set<pair<pair<ll,ll>,ll>>S; vector<pair<ll,ll>>V[LIM]; ll ans[LIM]; void DFS(int x, int o, ll a, ll b) { if(a<0) return; ans[x]=b; for(auto i : V[x]) if(i.st!=o) DFS(i.st, x, a-i.nd, b); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; rep(i, m) { ll a, b, c; cin >> a >> b >> c; --a; --b; if(a>b) swap(a, b); S.insert({{a, b}, c}); } while(q--) { int t; cin >> t; if(t==1) { ll a, b, c; cin >> a >> b >> c; --a; --b; if(a>b) swap(a, b); S.insert({{a, b}, c}); } else if(t==2) { ll a, b; cin >> a >> b; --a; --b; if(a>b) swap(a, b); S.erase(S.lower_bound({{a, b}, 0})); } else if(t==3) { rep(i, n) V[i].clear(); for(auto i : S) { V[i.st.st].pb({i.st.nd, i.nd}); V[i.st.nd].pb({i.st.st, i.nd}); } ll a, b, c; cin >> a >> b >> c; --a; DFS(a, a, b, c); } else { ll a; cin >> a; --a; cout << ans[a] << '\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 | #include<bits/stdc++.h> using namespace std; typedef long double ld; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const int LIM=2e5+7; set<pair<pair<ll,ll>,ll>>S; vector<pair<ll,ll>>V[LIM]; ll ans[LIM]; void DFS(int x, int o, ll a, ll b) { if(a<0) return; ans[x]=b; for(auto i : V[x]) if(i.st!=o) DFS(i.st, x, a-i.nd, b); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; rep(i, m) { ll a, b, c; cin >> a >> b >> c; --a; --b; if(a>b) swap(a, b); S.insert({{a, b}, c}); } while(q--) { int t; cin >> t; if(t==1) { ll a, b, c; cin >> a >> b >> c; --a; --b; if(a>b) swap(a, b); S.insert({{a, b}, c}); } else if(t==2) { ll a, b; cin >> a >> b; --a; --b; if(a>b) swap(a, b); S.erase(S.lower_bound({{a, b}, 0})); } else if(t==3) { rep(i, n) V[i].clear(); for(auto i : S) { V[i.st.st].pb({i.st.nd, i.nd}); V[i.st.nd].pb({i.st.st, i.nd}); } ll a, b, c; cin >> a >> b >> c; --a; DFS(a, a, b, c); } else { ll a; cin >> a; --a; cout << ans[a] << '\n'; } } } |