#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
#define x first
#define y second
#define ir(a, x, b) ((a) <= (x) && (x) <= (b))
#define vec vector
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
vec<set<pair<int, ll>>> g;
vec<int> col;
void dfs(int v, int p, int k, ll d) {
debug(v, p, k, d);
col[v] = k;
for (auto [c, dc] : g[v]) {
if (c == p) continue;
if (d < dc) continue;
dfs(c, v, k, d-dc);
}
}
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
g.resize(n);
col.resize(n);
while (m--) {
int a, b;
ll d;
cin >> a >> b >> d; --a, --b;
g[a].insert({b, d});
g[b].insert({a, d});
}
while (q--) {
int x; cin >> x;
debug(g);
if (x == 1) {
int a, b; ll d;
cin >> a >> b >> d; --a, --b;
g[a].insert({b, d});
g[b].insert({a, d});
} else if (x == 2) {
int a, b; cin >> a >> b; --a, --b;
g[a].erase(g[a].lower_bound({b, 0}));
g[b].erase(g[b].lower_bound({a, 0}));
} else if (x == 3) {
int v; ll d; int k;
cin >> v >> d >> k; --v;
dfs(v, v, k, d);
} else {
int i; cin >> i; --i;
cout << col[i] << "\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> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) #endif #define x first #define y second #define ir(a, x, b) ((a) <= (x) && (x) <= (b)) #define vec vector #define rep(i, a, b) for (int i = a; i < (b); ++i) #define all(x) (x).begin(), (x).end() using ll = long long; vec<set<pair<int, ll>>> g; vec<int> col; void dfs(int v, int p, int k, ll d) { debug(v, p, k, d); col[v] = k; for (auto [c, dc] : g[v]) { if (c == p) continue; if (d < dc) continue; dfs(c, v, k, d-dc); } } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q; cin >> n >> m >> q; g.resize(n); col.resize(n); while (m--) { int a, b; ll d; cin >> a >> b >> d; --a, --b; g[a].insert({b, d}); g[b].insert({a, d}); } while (q--) { int x; cin >> x; debug(g); if (x == 1) { int a, b; ll d; cin >> a >> b >> d; --a, --b; g[a].insert({b, d}); g[b].insert({a, d}); } else if (x == 2) { int a, b; cin >> a >> b; --a, --b; g[a].erase(g[a].lower_bound({b, 0})); g[b].erase(g[b].lower_bound({a, 0})); } else if (x == 3) { int v; ll d; int k; cin >> v >> d >> k; --v; dfs(v, v, k, d); } else { int i; cin >> i; --i; cout << col[i] << "\n"; } } return 0; } |
English