1 /**************************************************************
2 Problem: 2594
3 User: weeping
4 Language: C++
5 Result: Accepted
6 Time:25656 ms
7 Memory:103836 kb
8 ****************************************************************/
9
10 #include <bits/stdc++.h>
11
12 using namespace std;
13 namespace fastIO{
14 #define BUF_SIZE 500000
15 bool IOerror=0;
16 inline char nc(){
17 static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
18 if(p1==pend){
19 p1=buf;
20 pend=buf+fread(buf,1,BUF_SIZE,stdin);
21 if(pend==p1){
22 IOerror=1;
23 return -1;
24 }
25 }return *p1++;
26 }
27 inline bool blank(char ch){
28 return ch==‘ ‘||ch==‘\n‘||ch==‘\r‘||ch==‘\t‘;
29 }
30 inline bool read(int &x){
31 char ch;
32 while(blank(ch=nc()));
33 if(IOerror)return 0;
34 for(x=ch-‘0‘;(ch=nc())>=‘0‘&&ch<=‘9‘;x=x*10+ch-‘0‘);
35 return 1;
36 }
37 #undef BUF_SIZE
38 };
39
40 using namespace fastIO;
41
42 struct node
43 {
44 int u,v,w,f;
45 node(){}
46 node(int x,int y,int z){u=x,v=y,w=z;}
47 }eg[1000007],qs[100007];
48 int n,m,q,f[100007],vis[1000007],ans[100007];
49 map<pair<int,int>,int>hs;
50
51 struct Link_Cut_Tree
52 {
53 static const int MAXN = 1200000 + 7;
54
55 int ch[MAXN][2], fa[MAXN], rev[MAXN], sz[MAXN], v[MAXN], mx[MAXN], id[MAXN];
56 int sk[MAXN];
57
58 bool isroot(int x)
59 {
60 return ch[fa[x]][0] != x && ch[fa[x]][1] != x;
61 }
62
63 void reverse(int x)
64 {
65 rev[x] ^= 1, swap(ch[x][0],ch[x][1]);
66 }
67
68 void update(int x)
69 {
70 int lc = ch[x][0], rc = ch[x][1];
71 if(mx[lc]>mx[rc])
72 mx[x]=mx[lc],id[x]=id[lc];
73 else
74 mx[x]=mx[rc],id[x]=id[rc];
75 if(v[x]>mx[x])
76 mx[x]=v[x],id[x]=x;
77 }
78
79 void push_down(int x)
80 {
81 if(!rev[x]) return ;
82 if(ch[x][0]) reverse(ch[x][0]);
83 if(ch[x][1]) reverse(ch[x][1]);
84 rev[x]=0;
85 }
86
87 void rotate(int x)
88 {
89 int f = fa[x], gf = fa[f];
90 int t1 = ( x != ch[f][0]), t2 = ( f != ch[gf][0]), tmp = ch[x][1^t1];
91 if(!isroot(f)) ch[gf][0^t2] = x;
92 fa[tmp] = f, fa[x] = gf, ch[x][1^t1] = f, fa[f] = x, ch[f][0^t1] = tmp;
93 update(f);
94 }
95
96 void splay(int x)
97 {
98 int top = 0;
99 sk[++top] = x;
100 for(int i = x; !isroot(i); i = fa[i]) sk[++top] = fa[i];
101 while(top) push_down(sk[top--]);
102 for(int f = fa[x], gf = fa[f]; !isroot(x); rotate(x), f = fa[x],gf = fa[f])
103 if(!isroot(f))
104 rotate((x==ch[f][0]) ^ (f==ch[gf][0]) ? x : f);
105 update(x);
106 }
107
108 void access(int x)
109 {
110 for(int p = 0; x; p = x, x = fa[x])
111 splay(x), ch[x][1] = p, update(x);
112 }
113
114 void makeroot(int x)
115 {
116 access(x), splay(x), reverse(x);
117 }
118
119 int findroot(int x)
120 {
121 access(x), splay(x);
122 while(ch[x][0]) x = ch[x][0];
123 return x;
124 }
125 void link(int x,int y)
126 {
127 makeroot(x), fa[x] = y;
128 }
129
130 void cut(int x,int y)
131 {
132 makeroot(x), access(y), splay(y);
133 if(ch[y][0] == x) ch[y][0] = fa[x] = 0;
134 update(y);
135 }
136
137 int go(int op,int x,int y,int hid)
138 {
139 if(x>y) swap(x,y);
140 if(op==1)
141 {
142 makeroot(x),access(y),splay(y);
143 return mx[y];
144 }
145 if(findroot(x)!=findroot(y))
146 link(x,hid+n),link(hid+n,y);
147 else
148 {
149 makeroot(x),access(y),splay(y);
150 if(mx[y]>eg[hid].w)
151 {
152 int pp=id[y]-n;
153 cut(eg[pp].u,pp+n),cut(eg[pp].v,pp+n);
154 link(x,hid+n),link(hid+n,y);
155 }
156 }
157 return 0;
158 }
159 void debug(void)
160 {
161 for(int i=1;i<=100;i++)
162 printf("%d %d %d %d %d %d %d\n",i,fa[i],ch[i][0],ch[i][1],rev[i],sz[i]);
163 }
164 }lct;
165
166 int tid[1000007];
167 bool cmp(const int &ta,const int &tb)
168 {
169 return eg[ta].w<eg[tb].w;
170 }
171 int fd(int x)
172 {
173 return f[x]==x?x:f[x]=fd(f[x]);
174 }
175 void mintree(void)
176 {
177 for(int i=1;i<=n;i++) f[i]=i;
178 for(int i=1;i<=m;i++) tid[i]=i;
179 sort(tid+1,tid+1+m,cmp);
180 for(int i=1;i<=m;i++)
181 {
182 int p=tid[i];
183 if(vis[p]) continue;
184 int fa=fd(eg[p].u),fb=fd(eg[p].v);
185 if(fa==fb) continue;
186 f[fa]=fb,lct.link(eg[p].u,p+n),lct.link(eg[p].v,p+n);
187 }
188 }
189 int main(void)
190 {
191 //freopen("in.acm","r",stdin);
192 read(n),read(m),read(q);
193 for(int i=0;i<=n;i++) lct.v[i]=-1;
194 for(int i=1,x,y,z;i<=m;i++)
195 {
196 read(x),read(y),read(z),eg[i]=node(x,y,z);
197 if(x>y)swap(x,y);
198 hs[make_pair(x,y)]=i;
199 lct.v[i+n]=lct.mx[i+n]=z,lct.id[i+n]=i+n;
200 }
201 for(int i=1,op,x,y;i<=q;i++)
202 {
203 read(op),read(x),read(y),qs[i]=node(op,x,y);
204 if(x>y)swap(x,y);
205 qs[i].f=hs[make_pair(x,y)];
206 if(op==2)
207 vis[qs[i].f]=1;
208 }
209 mintree();
210 for(int i=q;i;i--)
211 ans[i]=lct.go(qs[i].u,qs[i].v,qs[i].w,qs[i].f);
212 for(int i=1;i<=q;i++)
213 if(qs[i].u==1)
214 printf("%d\n",ans[i]);
215 return 0;
216 }