#ifdef DEBUG_IS_VALID #define DEB 1 #define _LIBCPP_DEBUG 0 #else #define DEB 0 #define NDEBUG #endif #include using namespace std; #define ALL(g) (g).begin(),(g).end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define RREP(i, x, n) for(int i = x; i >= n; i--) #define rrep(i, n) RREP(i,n,0) #define pb push_back #pragma GCC optimize ("-O3") using namespace std; #define DUMPOUT cout #define dump(...) if(DEB) DUMPOUT<<" "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<ostream& operator << (ostream& os, pair p){cout << "(" << p.first << ", " << p.second << ")"; return os;} templateostream& operator << (ostream& os, vector& vec) { os << "{"; for (int i = 0; iostream& operator << (ostream& os, set& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;} templateostream& operator << (ostream& os, map mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; } void dump_func(){DUMPOUT << endl;} template void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);} template inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;} template inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;} using ll = long long; using P = pair; using Pl = pair; using vi = vector; using vvi = vector; using vl = vector; using vvl = vector; using vp = vector; using vvp = vector; const int INF = 1<<29; const long long LINF=1LL<<59; struct BiconnectedGraph{ using PInt = pair; int n, k; // k := the size of T vector > G, T, C; // G := original graph // T := compressed graph // C[u] := components \subeq V(G) | belongs to u \in V(T) vector ord, low, belong; // belong[u] := (the node in T which u\in G belongs to) vector B; BiconnectedGraph(){} BiconnectedGraph(const vector>& graph) :n(graph.size()), G(graph), C(graph.size()), T(graph.size()), k(0) { ord.resize(n); low.resize(n); belong.resize(n); fill(ord.begin(),ord.end(),-1); fill(belong.begin(),belong.end(),-1); for(int v = 0; v < n; v++){ if(ord[v]>=0) continue; dfs(v,-1,k); } k = 0; for(int i = 0; i < (int)B.size(); i++){ add_component(B[i].first,k); add_component(B[i].second,k); } for(int v=0;v ord[v]) swap(u,v); return ord[u] < low[v]; } void dfs(int v,int p,int &k){ ord[v] = low[v] = k; ++k; for(int u:G[v]){ if(u == p) continue; if(ord[u] >= 0){ low[v] = min(low[v],ord[u]); }else{ dfs(u,v,k); low[v] = min(low[v],low[u]); } if(is_bridge(u,v)) B.push_back(PInt(u,v)); } } void fill_component(int c,int v){ C[c].push_back(v); belong[v]=c; for(int u:G[v]){ if(belong[u]>=0||is_bridge(u,v)) continue; fill_component(c,u); } } void add_component(int v,int &k){ if(belong[v]>=0) return; fill_component(k++,v); } }; struct HLDecomposition { int n, pos; vector > graph; vector vid, head, sub, par, dep, inv, type; // vid[u] := the ordeing of u on decomposition // sub[u] := #(vertices of u-root subtree) // head[u] := the head of the line on decomposition // type[u] := the order of connected components HLDecomposition(){} HLDecomposition(const vector>& g, vector rs = {0}) :n(g.size()), pos(0), graph(g), vid(g.size(),-1), head(g.size()), sub(g.size(),1), par(g.size(), -1), dep(g.size(), 0), inv(g.size()), type(g.size()) { int c = 0; for(int r:rs){ dfs_sz(r); head[r] = r; dfs_hld(r, c++); } } void dfs_sz(int v) { for(int &u : graph[v]){ if(u == par[v]) continue; par[u] = v; dep[u] = dep[v] + 1; dfs_sz(u); sub[v] += sub[u]; if(sub[u] > sub[graph[v][0]]) swap(u,graph[v][0]); // sub[graph[v][0]] is largest } } void dfs_hld(int v,int c) { vid[v] = pos++; inv[vid[v]] = v; type[v] = c; for(int u : graph[v]){ if(u==par[v]) continue; head[u] = ( u == graph[v][0] ? head[v] : u); dfs_hld(u,c); } } // for_each(vertex) // [l,r] <- attention!! template void for_each(int u, int v, const F& f) { while(1){ if(vid[u] > vid[v]) swap(u,v); // vid[u] <= vid[v] f(max(vid[head[v]],vid[u]), vid[v]); if(head[u] != head[v]) v = par[head[v]]; else break; } } template T for_each(int u,int v,T ti,const Q &q,const F &f){ T l = ti, r = ti; while(1){ if(vid[u] > vid[v]){ swap(u,v); swap(l,r); } l = f(l, q(max(vid[head[v]], vid[u]), vid[v])); if(head[u] != head[v]) v = par[head[v]]; else break; } return f(l,r); } // for_each(edge) // [l,r] <- attention!! template void for_each_edge(int u, int v,const F& f) { while(1){ if(vid[u] > vid[v]) swap(u,v); if(head[u] != head[v]){ f(vid[head[v]], vid[v]); v = par[head[v]]; }else{ if(u!=v) f(vid[u]+1, vid[v]); break; } } } int edge_id(int u, int v){ // vid of the farther one of {u, v} int ch = dep[u] > dep[v] ? u : v; return vid[ch]; } int lca(int u,int v){ while(1){ if(vid[u] > vid[v]) swap(u,v); if(head[u]==head[v]) return u; v = par[head[v]]; } } int distance(int u,int v){ return dep[u] + dep[v] - 2 * dep[lca(u,v)]; } }; template class SegmentTree{ private: using T = typename Monoid::type; int sz, N; vector dat; public: SegmentTree(const vector &vec){ sz = vec.size(); N = 1; while(N=0;i--) dat[i]=Monoid::op(dat[2*i+1],dat[2*i+2]); } SegmentTree(const int n){ sz = n; N = 1; while(N=0;i--) dat[i]=Monoid::op(dat[2*i+1],dat[2*i+2]); } void update(int i,T val){ assert(0<=i && i0){ i=(i-1)/2; dat[i]=Monoid::op(dat[2*i+1],dat[2*i+2]); } return; } T query(int a,int b){ // op[a,b) return query(a,b,0,0,N);} T query(int a,int b,int k,int l,int r){ assert(0<=l && l<=r && r<2*N); if(r<=a || b<=l) return Monoid::id(); else if(a<=l && r<=b) return dat[k]; else{ T lval=query(a,b,2*k+1,l,(l+r)/2); T rval=query(a,b,2*k+2,(l+r)/2,r); return Monoid::op(lval,rval); } } }; struct RMQ{ using type = Pl; static type id(){return Pl(-LINF,-LINF);} static type op(const type &a ,const type &b){return max(a,b);} }; int main(){ ll N, M, Q; cin >> N >> M >> Q ; vvi g(N); rep(i,M){ int a,b; cin >> a >> b ; a--; b--; g[a].pb(b); g[b].pb(a); } BiconnectedGraph bic(g); ll sz = bic.k; HLDecomposition hld(bic.T); SegmentTree rmq(sz+2); vector> que(sz); Pl t = {-LINF, -LINF}; auto qry = [&](int u, int v){ chmax(t,rmq.query(u, v+1)); }; rep(q,Q){ ll a,b,c; cin >> a >> b >> c ; if(a==1){ b--; int num = bic.belong[b]; // index in bic.T if(que[num].empty() || c > que[num].top()){ rmq.update(num, Pl(c, num)); } que[num].push(c); }else{ t = {-LINF, -LINF}; int u, v; u = bic.belong[b-1]; v = bic.belong[c-1]; hld.for_each(u, v, qry); cout << (t.first != -LINF ? t.first : -1) << endl; if(t.first != -LINF){ que[t.second].pop(); if(!que[t.second].empty()) rmq.update(t.second, Pl(que[t.second].top(), t.second)); else rmq.update(t.second, Pl(-LINF,-LINF)); } } } return 0; }