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
#include <bits/stdc++.h>
using namespace std;

constexpr int MAXN = 2e5 + 5;

vector<pair<int, int>> adj[MAXN];
map<pair<int, int>, bool> exist;
vector<bool> vis;
int color[MAXN];

void dfs(int v, int d, int col)
{
    vis[v] = 1;
    color[v] = col;
    for (auto x : adj[v])
    {
        if (vis[x.first] || d - x.second < 0)
            continue;
        dfs(x.first, d - x.second, col);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
        exist[{min(a, b), max(a, b)}] = 1;
    }

    for (int i = 0; i < q; i++)
    {
        int x;
        cin >> x;
        if (x == 1)
        {
            int a, b, c;
            cin >> a >> b >> c;
            adj[a].push_back({b, c});
            adj[b].push_back({a, c});
            exist[{min(a, b), max(a, b)}] = 1;
        }
        else if (x == 2)
        {
            int a, b;
            cin >> a >> b;
            exist[{min(a, b), max(a, b)}] = 0;
        }
        else if (x == 3)
        {
            int a, b, c;
            cin >> a >> b >> c;
            vis.assign(MAXN, 0);
            dfs(a, b, c);
        }
        else
        {
            int a;
            cin >> a;
            cout << color[a] << '\n';
        }
    }

    return 0;
}