#include <bits/stdc++.h> using namespace std; vector<pair<int, int>> neighbours[200000]; int colors[200000]; void add(int a, int b, int d) { neighbours[a].push_back(make_pair(b, d)); neighbours[b].push_back(make_pair(a, d)); } void del(int a, int b) { for (int i=0; i<200000; i++) { if (neighbours[a][i].first == b) { neighbours[a].erase(neighbours[a].begin()+i); break; } } for (int i=0; i<200000; i++) { if (neighbours[b][i].first == a) { neighbours[b].erase(neighbours[b].begin()+i); break; } } } void paint(int v, long long z, int k, int p=-1) { colors[v] = k; for (auto e : neighbours[v]) { if (e.first == p) continue; if (z < e.second) continue; paint(e.first, z-e.second, k, v); } } void ask(int u) { printf("%d\n", colors[u]); } int main() { int n, m, q; scanf("%d %d %d", &n, &m, &q); int a, b, d; for (int i=0; i<m; i++) { scanf("%d %d %d", &a, &b, &d); add(a-1, b-1, d); } int t; long long z; for (int i=0; i<q; i++) { scanf("%d", &t); switch (t) { case 1: scanf("%d %d %d", &a, &b, &d); add(a-1, b-1, d); break; case 2: scanf("%d %d", &a, &b); del(a-1, b-1); break; case 3: scanf("%d %lld %d", &a, &z, &b); paint(a-1, z, b); break; case 4: scanf("%d", &a); ask(a-1); break; } } 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | #include <bits/stdc++.h> using namespace std; vector<pair<int, int>> neighbours[200000]; int colors[200000]; void add(int a, int b, int d) { neighbours[a].push_back(make_pair(b, d)); neighbours[b].push_back(make_pair(a, d)); } void del(int a, int b) { for (int i=0; i<200000; i++) { if (neighbours[a][i].first == b) { neighbours[a].erase(neighbours[a].begin()+i); break; } } for (int i=0; i<200000; i++) { if (neighbours[b][i].first == a) { neighbours[b].erase(neighbours[b].begin()+i); break; } } } void paint(int v, long long z, int k, int p=-1) { colors[v] = k; for (auto e : neighbours[v]) { if (e.first == p) continue; if (z < e.second) continue; paint(e.first, z-e.second, k, v); } } void ask(int u) { printf("%d\n", colors[u]); } int main() { int n, m, q; scanf("%d %d %d", &n, &m, &q); int a, b, d; for (int i=0; i<m; i++) { scanf("%d %d %d", &a, &b, &d); add(a-1, b-1, d); } int t; long long z; for (int i=0; i<q; i++) { scanf("%d", &t); switch (t) { case 1: scanf("%d %d %d", &a, &b, &d); add(a-1, b-1, d); break; case 2: scanf("%d %d", &a, &b); del(a-1, b-1); break; case 3: scanf("%d %lld %d", &a, &z, &b); paint(a-1, z, b); break; case 4: scanf("%d", &a); ask(a-1); break; } } return 0; } |