#include #pragma GCC optimize("O3") #pragma GCC target("avx") #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)< P; typedef pair pll; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector vvl; typedef vector vd; typedef vector

vp; typedef vector vs; const int MAX_N = 100005; #define getchar getchar_unlocked #define putchar putchar_unlocked int in() { int n, c; while ((c = getchar()) < '0') if (c == EOF) return -1; n = c - '0'; while ((c = getchar()) >= '0') n = n * 10 + c - '0'; return n; } void out(int n) { int res[11], i = 0; do { res[i++] = n % 10, n /= 10; } while (n); while (i) putchar(res[--i] + '0'); putchar('\n'); } class HLdecomposition{ public: int V; vector > G; vector stsize, parent, pathtop, in, out; void BuildStsize(int u, int p){ stsize[u] = 1, parent[u] = p; for(int& v : G[u]){ if(v == p) continue; BuildStsize(v, u); stsize[u] += stsize[v]; if(stsize[v] > stsize[G[u][0]]){ swap(v, G[u][0]); } } } void BuildPath(int u, int p, int& tm){ in[u] = tm++; for(int v : G[u]){ if(v == p) continue; pathtop[v] = (v == G[u][0] ? pathtop[u] : v); BuildPath(v, u, tm); } out[u] = tm; } public: void add_edge(int u, int v){ G[u].push_back(v), G[v].push_back(u); } void build(){ int tm = 0; BuildStsize(0, -1), BuildPath(0, -1, tm); } //元の頂点のインデックスの配列上でのidを返す inline int get(int a){ return in[a]; } int lca(int a, int b){ int pa = pathtop[a], pb = pathtop[b]; while(pathtop[a] != pathtop[b]){ if(in[pa] > in[pb]){ a = parent[pa], pa = pathtop[a]; }else{ b = parent[pb], pb = pathtop[b]; } } if(in[a] > in[b]) swap(a, b); return a; } void subtree_query(int a, const function< void(int, int) > &func){ func(in[a], out[a]); } void path_query(int a, int b, const function< void(int, int) > &func){ int pa = pathtop[a], pb = pathtop[b]; while(pathtop[a] != pathtop[b]){ if(in[pa] > in[pb]){ func(in[pa], in[a] + 1); a = parent[pa], pa = pathtop[a]; }else{ func(in[pb], in[b] + 1); b = parent[pb], pb = pathtop[b]; } } if(in[a] > in[b]) swap(a, b); func(in[a], in[b] + 1); } void construct(int node_size){ V = node_size, G.resize(V), stsize.resize(V, 0), parent.resize(V, -1), pathtop.resize(V, -1), in.resize(V, -1), out.resize(V, -1); } }; class biconnected{ public: using P = pair; int V, kind; vector > G,tree; vector > check; vector ord,low,cmp; vector

bridge; vector visit; biconnected(int node_size) : V(node_size), kind(0), G(V), check(V), ord(V), low(V) ,cmp(V), visit(V, false){} void build(){ int id = 0; for(int i = 0; i < V; i++){ if(!visit[i]){ dfs(i,-1,id); } } } void dfs(int u,int p,int &k) { visit[u] = true; ord[u] = k++; low[u] = ord[u]; for(int i = 0; i < (int)G[u].size(); i++){ int v = G[u][i]; if(!visit[v]){ dfs(v,u,k); low[u] = min(low[u],low[v]); if(ord[u] < low[v]){ bridge.push_back(P(u,v)); check[u][i].second = 1; check[v][check[u][i].first].second = 1; } //(v,w)は後退辺 }else if(v != p){ low[u] = min(low[u],ord[v]); } } } void add_edge(int u,int v) { G[u].push_back(v),G[v].push_back(u); check[u].push_back(P((int)check[v].size(),0)); check[v].push_back(P((int)check[u].size()-1,0)); } void restrict_dfs(int u,int p,int kind,queue& que) { visit[u] = true; cmp[u] = kind; for(int i = 0; i < (int)G[u].size(); i++){ int v = G[u][i]; if(check[u][i].second){ if(!visit[v]){ que.push(v); } }else if(!visit[v]){ restrict_dfs(v,u,kind,que); } } } void rebuild() { fill(visit.begin(),visit.end(),false); for(int i = 0; i < V; i++){ if(!visit[i]){ queue que; que.push(i); while(!que.empty()){ int p = que.front(); que.pop(); restrict_dfs(p,-1,kind,que); kind++; } } } } // 2(辺)連結成分を頂点とする木を作る void make_bctree(HLdecomposition& hl) { rebuild(); hl.construct(kind); for(int i = 0; i < (int)bridge.size(); i++){ int a = cmp[bridge[i].first], b = cmp[bridge[i].second]; hl.add_edge(a, b); } } }; #define T int class segtree { private: int n,sz; vector > node; public: segtree(vector& v){ sz = (int)v.size(); n = 1; while(n < sz){ n *= 2; } node.resize(2*n); rep(i,sz){ node[i+n] = make_pair(v[i], i); } for(int i=n-1; i>=1; i--){ node[i] = min(node[2*i], node[2*i+1]); } } void update(int k, T a) { node[k+=n] = make_pair(a, k); while(k>>=1){ node[k] = min(node[2*k], node[2*k+1]); } } pair query(int a,int b,int k=0,int l=0,int r=-1) { pair res1 = make_pair(numeric_limits::max(), -1); pair res2 = make_pair(numeric_limits::max(), -1); a += n, b += n; while(a != b){ if(a % 2) cmn(res1, node[a++]); if(b % 2) cmn(res2, node[--b]); a >>= 1, b>>= 1; } return min(res1, res2); } void print() { rep(i,sz){ pair p; p = query(i,i+1); cout << "st[" << i << "]: " << p.fi << " " << p.se << endl; } } }; int main() { int n,m,q; n = in(), m = in(), q = in(); biconnected bc(n); rep(i,m){ int u = in(), v = in(); bc.add_edge(u-1,v-1); } bc.build(); HLdecomposition hl; bc.make_bctree(hl); hl.build(); int& kind = bc.kind; vi& cmp = bc.cmp; vi u(kind,0); vector > que(kind); vector mx(kind,0); vector trans(kind); vector unzip(kind); rep(i,kind){ int res = hl.get(i); trans[i] = res; unzip[res] = i; } segtree seg(u); rep(i,q){ int p,q,r; p = in(), q = in(), r = in(); if(p == 1){ int id = cmp[q-1]; que[id].push(r); if(mx[id] < r){ mx[id] = r; seg.update(trans[id],-r); } }else{ int id1 = cmp[q-1],id2 = cmp[r-1]; P ans = P(0,-1); hl.path_query(id1,id2,[&](int l, int r){ ans = min(ans,seg.query(l, r)); }); if(ans.fi == 0){ putchar('-'), putchar('1'), putchar('\n'); }else{ int real_id = unzip[ans.se]; que[real_id].pop(); if(que[real_id].empty()){ seg.update(ans.se,0); mx[real_id] = 0; }else{ int res = que[real_id].top(); seg.update(ans.se,-res); mx[real_id] = res; } out(-ans.fi); } } } }