#include <iostream>
#include <vector>
#include <utility>
#include <limits>
using namespace std;
const int MXV = 200007;
vector<bool> vis(MXV);
vector<int> colored(MXV);
void dfs(vector<vector<pair<int, int>>> &v, int idx, int z, int k)
{
vis[idx] = true;
colored[idx] = k;
for (auto i : v[idx])
{
if (i.second <= z && !vis[i.first])
{
dfs(v, i.first, z - i.second, k);
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, q, a, b, d, k, lb, del = 0;
cin >> n >> m >> q;
vector<vector<pair<int, int>>> v(MXV);
for (int i = 0; i < m; i++)
{
cin >> a >> b >> d;
v[a].push_back({b, d});
v[b].push_back({a, d});
}
for (int i = 0; i < q; i++)
{
cin >> lb;
if (lb == 1)
{
cin >> a >> b >> d;
v[a].push_back({b, d});
v[b].push_back({a, d});
}
if (lb == 2)
{
cin >> a >> b;
for (auto it = v[a].begin(); it != v[a].end(); ++it)
{
if (it->first == b)
{
v[a].erase(it);
break;
}
}
for (auto it = v[b].begin(); it != v[b].end(); ++it)
{
if (it->first == a)
{
v[b].erase(it);
break;
}
}
}
if (lb == 3)
{
cin >> a >> b >> k;
if (a < MXV && b <= numeric_limits<int>::max() && k <= numeric_limits<int>::max())
{
dfs(v, a, b, k);
vis.assign(MXV, false);
}
}
if (lb == 4)
{
cin >> a;
if (a < MXV)
{
cout << colored[a] << endl;
}
}
}
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 92 93 94 95 96 97 98 99 | #include <iostream> #include <vector> #include <utility> #include <limits> using namespace std; const int MXV = 200007; vector<bool> vis(MXV); vector<int> colored(MXV); void dfs(vector<vector<pair<int, int>>> &v, int idx, int z, int k) { vis[idx] = true; colored[idx] = k; for (auto i : v[idx]) { if (i.second <= z && !vis[i.first]) { dfs(v, i.first, z - i.second, k); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, q, a, b, d, k, lb, del = 0; cin >> n >> m >> q; vector<vector<pair<int, int>>> v(MXV); for (int i = 0; i < m; i++) { cin >> a >> b >> d; v[a].push_back({b, d}); v[b].push_back({a, d}); } for (int i = 0; i < q; i++) { cin >> lb; if (lb == 1) { cin >> a >> b >> d; v[a].push_back({b, d}); v[b].push_back({a, d}); } if (lb == 2) { cin >> a >> b; for (auto it = v[a].begin(); it != v[a].end(); ++it) { if (it->first == b) { v[a].erase(it); break; } } for (auto it = v[b].begin(); it != v[b].end(); ++it) { if (it->first == a) { v[b].erase(it); break; } } } if (lb == 3) { cin >> a >> b >> k; if (a < MXV && b <= numeric_limits<int>::max() && k <= numeric_limits<int>::max()) { dfs(v, a, b, k); vis.assign(MXV, false); } } if (lb == 4) { cin >> a; if (a < MXV) { cout << colored[a] << endl; } } } return 0; } |
English