#include using namespace std; #define int long long struct BiconectedGraph{ typedef pair P; vector > G,C,T; vector ord,low,belong; vector

B; int V; BiconectedGraph(){} BiconectedGraph(int n){ G.clear(); C.clear(); T.clear(); G.resize(n); C.resize(n); T.resize(n); } bool is_bridge(int u,int v){ if(ord[u]>ord[v]) swap(u,v); return ord[u]=0){ low[u]=min(low[u],ord[v]); }else{ dfs(v,u,k); low[u]=min(low[u],low[v]); } if(is_bridge(u,v)) B.push_back(P(u,v)); } } void fill_component(int c,int u){ C[c].push_back(u); belong[u]=c; for(int v:G[u]){ if(belong[v]>=0||is_bridge(u,v)) continue; fill_component(c,v); } } void add_component(int u,int &k){ if(belong[u]>=0) return; fill_component(k++,u); } void biconnectedgraph(int n){ int k=0; ord.clear(); ord.resize(n,-1); low.clear(); low.resize(n); belong.clear(); belong.resize(n,-1); for(int u=0;u=0) continue; dfs(u,-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); } add_component(0,k); V=k; for(int i=0;i<(int)B.size();i++){ int u=belong[B[i].first],v=belong[B[i].second]; T[u].push_back(v); T[v].push_back(u); } } }; struct HLDecomposition { vector> g; // vid, head, heavy, parent は必須 // depth, inv は使用する機能によっては不要 vector vid, head, heavy, parent, depth, inv; HLDecomposition(int n) : g(n), vid(n, -1), head(n), heavy(n, -1), parent(n), depth(n), inv(n) {} // 辺 (u, v) を追加する void add(int u, int v) { g[u].push_back(v); //g[v].push_back(u); } // 構築する void build() { dfs(0, -1); bfs(); } int dfs(int curr, int prev) { parent[curr] = prev; int sub = 1, max_sub = 0; for (int next : g[curr]) if (next != prev) { depth[next] = depth[curr] + 1; int sub_next = dfs(next, curr); sub += sub_next; if (max_sub < sub_next) max_sub = sub_next, heavy[curr] = next; } return sub; } void bfs() { int k = 0; queue q({ 0 }); while (!q.empty()) { int h = q.front(); q.pop(); for (int i = h; i != -1; i = heavy[i]) { vid[i] = k++; //cout< f) { if (vid[u] > vid[v]) swap(u, v); f(max(vid[head[v]], vid[u]), vid[v]); if (head[u] != head[v]) for_each(u, parent[head[v]], f); } }; struct RMQ{ int n; vector > dat; RMQ(){} RMQ(int n_){init(n_);} void init(int n_){ n=1; while(n0){ k=(k-1)/2; assert(!dat[k].count(a)); dat[k].insert(a); } } void remove(int k,int a){ //cout<0){ k=(k-1)/2; assert(dat[k].count(a)); dat[k].erase(a); } } int query(int a,int b,int k,int l,int r){ if(r<=a||b<=l) return -1; if(a<=l&&r<=b){ if(dat[k].empty()) return -1; return *--dat[k].end(); } int vl=query(a,b,k*2+1,l,(l+r)/2); int vr=query(a,b,k*2+2,(l+r)/2,r); return max(vl,vr); } int query(int a,int b){ //cout<>n>>e>>q; BiconectedGraph big(n); for(int i=0;i>s>>t; s--;t--; //cout<"< m; int num=0; set as; for(int i=0;i>d; if(d==1){ int u,w; cin>>u>>w; u--; u=big.belong[u]; u=hl.vid[u]; //cout<>s>>t; s--;t--; s=big.belong[s]; t=big.belong[t]; int ans=-1; //cout<