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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<pii>;

const int N = 2e5 + 10;
int kolor[N];
int vis[N];
unordered_map<int, int> G[N];

void add_edge(int u, int v, ll w) {
  G[u][v] = w;
  G[v][u] = w;
}

void remove_edge(int u, int v) {
  G[u].erase(v);
  G[v].erase(u);
}

int cnt = 0;

void dfs(int v, ll z, int k) {
  vis[v] = cnt;
  if (z < 0)
    return;

  kolor[v] = k;

  for (auto u : G[v]) {
    if (vis[u.first] < cnt) {
      dfs(u.first, z - u.second, k);
    }
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();

  int n, m, q;
  cin >> n >> m >> q;

  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    add_edge(a, b, c);
  }

  for (int i = 0; i < q; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int a, b, c;
      cin >> a >> b >> c;
      add_edge(a, b, c);
    }
    if (t == 2) {
      int a, b;
      cin >> a >> b;
      remove_edge(a, b);
    }
    if (t == 3) {
      int a, b;
      ll z;
      cin >> a >> z >> b;
      cnt++;
      dfs(a, z, b);
    }

    if (t == 4) {
      int a;
      cin >> a;
      cout << kolor[a] << "\n";
    }
  }
}