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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <bits/stdc++.h>

using namespace std;

const int N = 200'000 + 7;
const int Q = 200'000 + 7;

mt19937 rng(2137);

struct Query {
	int op;
	int a, b, d;
	long long z;
};

int n, m, q;
vector<tuple<int, int, int>> edges;
Query queries[Q];

namespace BRUTE {

set<pair<int, int>> adj[N];
map<pair<int, int>, int> all_edges;
int color[N];

void update(int u, int f, long long z, int k) {
	color[u] = k;

	for (auto [d, v] : adj[u]) if (v != f) {
		if (d > z)
			break;

		update(v, u, z - d, k);
	}
}

void solve() {
	for (auto [a, b, d] : edges) {
		if (a > b)
			swap(a, b);

		adj[a].emplace(d, b);
		adj[b].emplace(d, a);

		all_edges[make_pair(a, b)] = d;
	}

	for (int i = 1; i <= q; i++) {
		Query query = queries[i];

		if (query.op == 1) {
			int a = query.a, b = query.b, d = query.d;

			if (a > b)
				swap(a, b);

			adj[a].emplace(d, b);
			adj[b].emplace(d, a);

			all_edges[make_pair(a, b)] = d;
		}
		else
		if (query.op == 2) {
			int a = query.a, b = query.b;

			if (a > b)
				swap(a, b);

			int w = all_edges[make_pair(a, b)];
			
			adj[a].erase(make_pair(w, b));
			adj[b].erase(make_pair(w, a));
		}
		else
		if (query.op == 3) {
			int v = query.a, k = query.d;
			long long z = query.z;

			update(v, -1, z, k);
		}
		else
		if (query.op == 4) {
			int u = query.a;

			cout << color[u] << '\n';
		}
		else {
			assert(false);
		}
	}
}

}

int main() {
	ios::sync_with_stdio(false), cin.tie(nullptr);

	cin >> n >> m >> q;
	for (int i = 1; i <= m; i++) {
		int a, b, d;
		cin >> a >> b >> d;

		edges.emplace_back(a, b, d);
	}

	bool subtask1 = true;
	bool subtask2 = true;

	for (int i = 1; i <= q; i++) {
		Query &query = queries[i];

		int &op = query.op;
		cin >> op;
	
		if (op == 1) {
			cin >> query.a >> query.b >> query.d;
			subtask1 = false;
		}
		else
		if (op == 2) {
			cin >> query.a >> query.b;
			subtask1 = false;
		}
		else
		if (op == 3) {
			cin >> query.a >> query.z >> query.d;
			if (query.z != 1'000'000'000'000'000LL) {
				subtask2 = false;
			}
		}
		else
		if (op == 4)
			cin >> query.a;
		else
			assert(false);
	}
	
	BRUTE::solve();
}