#include <bits/stdc++.h> #define int unsigned long long using namespace std; vector<int> color; vector<map<int, int>> v; void dfs(int vi, int k, int z, int p = -1) { if (z < 0) return; color[vi] = k; for (auto [to, l] : v[vi]) { if (to != p) { dfs(to, k, z - v[vi][to], vi); } } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; v.resize(n); while(m--) { int a, b, d; cin >> a >> b >> d; a--; b--; v[a][b] = d; v[b][a] = d; } color.assign(n, 0); while (q--) { int t; cin >> t; if (t == 1) { int a, b, d; cin >> a >> b >> d; a--; b--; v[a][b] = d; v[b][a] = d; } else if (t == 2) { int a, b; cin >> a >> b; a--; b--; v[a][b] = 0; v[b][a] = 0; } else if (t == 3) { int vi, z, k; cin >> vi >> z >> k; vi--; dfs(vi, k, z); } else if (t == 4) { int u; cin >> u; u--; cout << color[u] << "\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 57 58 59 60 61 62 63 64 65 66 67 68 | #include <bits/stdc++.h> #define int unsigned long long using namespace std; vector<int> color; vector<map<int, int>> v; void dfs(int vi, int k, int z, int p = -1) { if (z < 0) return; color[vi] = k; for (auto [to, l] : v[vi]) { if (to != p) { dfs(to, k, z - v[vi][to], vi); } } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, q; cin >> n >> m >> q; v.resize(n); while(m--) { int a, b, d; cin >> a >> b >> d; a--; b--; v[a][b] = d; v[b][a] = d; } color.assign(n, 0); while (q--) { int t; cin >> t; if (t == 1) { int a, b, d; cin >> a >> b >> d; a--; b--; v[a][b] = d; v[b][a] = d; } else if (t == 2) { int a, b; cin >> a >> b; a--; b--; v[a][b] = 0; v[b][a] = 0; } else if (t == 3) { int vi, z, k; cin >> vi >> z >> k; vi--; dfs(vi, k, z); } else if (t == 4) { int u; cin >> u; u--; cout << color[u] << "\n"; } } return 0; } |