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
// Author: Bartek Knapik

#include <cstdio>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

const int MAX_N = 200000 + 9;

int n, m, q, a, b, v, k, cmd;
long long d, z;

int color[MAX_N];
bool visited[MAX_N];
unordered_map<long long, long long> edges;
unordered_set<int> adj[MAX_N];


void dfs(int _v, long long _z, int _k)
{
	if (_z < 0) return;
	color[_v] = _k;
	visited[_v] = true;
	for (auto it = adj[_v].begin(); it != adj[_v].end(); ++it)
	{
		if (visited[*it]) continue;
		a = _v;
		b = *it;
		if (b > a) { int tmp = a; a = b; b = tmp; }
		dfs(*it, _z - edges[((long long)a << 20) + (long long)b], _k);
	}
}

void add() 
{
	scanf("%d%d%lld", &a, &b, &d);
	adj[a].insert(b);
	adj[b].insert(a);
	if (b > a) { int tmp = a; a = b; b = tmp; }
	edges[((long long)a << 20) + (long long)b] = d;
}

void rem()
{
	scanf("%d%d", &a, &b);
	adj[a].erase(b);
	adj[b].erase(a);
	if (b > a) { int tmp = a; a = b; b = tmp; }
	edges.erase(((long long)a << 20) + (long long)b);
}

void col()
{
	scanf("%d%lld%d", &v, &z, &k);
	for (int i = 0; i < MAX_N; ++i) visited[i] = false;
	dfs(v, z, k);
}

void ask()
{
	scanf("%d", &a);
	printf("%d\n", color[a]);
}

int main()
{
    scanf("%d%d%d", &n, &m, &q);

	for (int i = 0; i < m; ++i)
		add();
	
	for (int i = 0; i < q; ++i)
	{
		scanf("%d", &cmd);
		if (cmd == 1) add();
		else if (cmd == 2) rem();
		else if (cmd == 3) col();
		else ask();
	}
    return 0;
}