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;

typedef pair<long long, long long> par;
vector<par> graf[200009];
map<long long, long long> ma[200009];
int col[200009];
long long z, k;

void DFS(int u, long long odl, int ojc)
{
	col[u] = k;
	long long a, b;
	for(int i=0; i<graf[u].size(); i++)
	{
		a = graf[u][i].first;
		b = graf[u][i].second;
		if(ma[u].find(a) != ma[u].end())
		{
			if(ma[u][a] > 0) 
			{
				b = ma[u][a];
				graf[u][i].second = ma[u][a];
			}
			else
			{
				swap(graf[u][i], graf[u][graf[u].size()-1]);
				graf[u].pop_back();
				ma[u].erase(a);
				i--;
				continue;
			}
			ma[u].erase(a);
		}
		if(a != ojc && odl + b <= z) DFS(a, odl+b, u);
	}
	return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
	long long n, m, q, a, b, c;
	cin>>n>>m>>q;
	for(int i=1; i<=m; i++)
	{
		cin>>a>>b>>c;
		graf[a].push_back(par(b, c));
		graf[b].push_back(par(a, c));
	}
	while(q--)
	{
		cin>>a;
		if(a == 1)
		{
			cin>>a>>b>>c;
			if(ma[a].find(b) == ma[a].end()) graf[a].push_back(par(b, c));
			else ma[a][b] = c;
			if(ma[b].find(a) == ma[b].end()) graf[b].push_back(par(a, c));
			else ma[b][a] = c;
		}
		else if(a == 2)
		{
			cin>>a>>b;
			if(ma[a].find(b) == ma[a].end()) ma[a].insert(par(b, -1));
			else ma[a][b] = -1;
			if(ma[b].find(a) == ma[b].end()) ma[b].insert(par(a, -1));
			else ma[b][a] = -1;
		}
		else if(a == 3)
		{
			cin>>b>>z>>k;
			DFS(b, 0, -1);
		}
		else
		{
			cin>>b;
			cout<<col[b]<<"\n";
		}
	}
    return 0;
}