#include using namespace std; using ll=long long; using ull=unsigned long long; using P=pair; templateusing minque=priority_queue,greater>; templatebool chmax(T &a,const T &b){return (abool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} templateistream &operator>>(istream &is,pair&p){is>>p.first>>p.second;return is;} templateistream &operator>>(istream &is,tuple&a){is>>std::get<0>(a)>>std::get<1>(a)>>std::get<2>(a);return is;} templateistream &operator>>(istream &is,array&a){for(auto&i:a)is>>i;return is;} templateistream &operator>>(istream &is,vector &a){for(auto &i:a)is>>i;return is;} templatevoid operator++(pair&a,int n){a.first++,a.second++;} templatevoid operator--(pair&a,int n){a.first--,a.second--;} templatevoid operator++(vector&a,int n){for(auto &i:a)i++;} templatevoid operator--(vector&a,int n){for(auto &i:a)i--;} #define overload3(_1,_2,_3,name,...) name #define rep1(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,l,r) for(int i=(int)(l);i<(int)(r);i++) #define rep(...) overload3(__VA_ARGS__,rep2,rep1)(__VA_ARGS__) #define reps(i,l,r) rep2(i,l,r) #define all(x) x.begin(),x.end() #define pcnt(x) __builtin_popcountll(x) #define fin(x) return cout<<(x)<<'\n',static_cast(0) #define yn(x) cout<<((x)?"Yes\n":"No\n") #define uniq(x) sort(all(x)),x.erase(unique(all(x)),x.end()) template inline int fkey(vector&z,T key){return lower_bound(z.begin(),z.end(),key)-z.begin();} ll myceil(ll a,ll b){return (a+b-1)/b;} template auto vec(const int (&d)[n],const T &init=T()){ if constexpr (id(d,init)); else return init; } #ifdef LOCAL #include #define SWITCH(a,b) (a) #else #define debug(...) static_cast(0) #define debugg(...) static_cast(0) #define SWITCH(a,b) (b) templateostream &operator<<(ostream &os,const pair&p){os<>testcase; for(int i=0;i struct has_update_impl{ template static auto check(T&&x)->decltype(x.update(),std::true_type{}); template static auto check(...)->std::false_type; }; template struct has_update:public decltype(has_update_impl::check(std::declval())){}; template inline constexpr bool has_update_v=has_update::value; struct has_push_impl{ template static auto check(T&&x)->decltype(x.push(),std::true_type{}); template static auto check(...)->std::false_type; }; template struct has_push:public decltype(has_push_impl::check(std::declval())){}; template inline constexpr bool has_push_v=has_push::value; struct has_middle_impl{ template static auto check(T&&x)->decltype(x.middle,std::true_type{}); template static auto check(...)->std::false_type; }; template struct has_middle:public decltype(has_middle_impl::check(std::declval())){}; template inline constexpr bool has_middle_v=has_middle::value; template void splay(T*nd){ if constexpr(has_push_v&&!no_push)nd->push(); while(nd->par){ T *p=nd->par; T *pp=p->par; if constexpr(has_push_v&&!no_push){ if(pp)pp->push(); p->push(); nd->push(); } if(p->left==nd){ if(pp){ if(pp->left==p){ nd->par=pp->par; if(pp->par){ if constexpr(has_middle_v){ if(pp->par->middle==pp)nd->par->middle=nd; else if(pp->par->left==pp)nd->par->left=nd; else if(pp->par->right==pp)nd->par->right=nd; } else{ if(pp->par->left==pp)nd->par->left=nd; else if(pp->par->right==pp)nd->par->right=nd; } } pp->left=p->right; if(pp->left)pp->left->par=pp; p->left=nd->right; if(p->left)p->left->par=p; nd->right=p; p->par=nd; p->right=pp; pp->par=p; if constexpr(has_update_v)pp->update(),p->update(),nd->update(); continue; } else if(pp->right==p){ nd->par=pp->par; if(pp->par){ if constexpr(has_middle_v){ if(pp->par->middle==pp)nd->par->middle=nd; else if(pp->par->left==pp)nd->par->left=nd; else if(pp->par->right==pp)nd->par->right=nd; } else{ if(pp->par->left==pp)nd->par->left=nd; else if(pp->par->right==pp)nd->par->right=nd; } } p->left=nd->right; if(p->left)p->left->par=p; pp->right=nd->left; if(pp->right)pp->right->par=pp; nd->left=pp; pp->par=nd; nd->right=p; p->par=nd; if constexpr(has_update_v)pp->update(),p->update(),nd->update(); continue; } } nd->par=pp; if(pp){ if constexpr(has_middle_v){ if(pp->middle==p)pp->middle=nd; else if(pp->left==p)pp->left=nd; else if(pp->right==p)pp->right=nd; } else{ if(pp->left==p)pp->left=nd; else if(pp->right==p)pp->right=nd; } } p->left=nd->right; if(p->left)p->left->par=p; nd->right=p; p->par=nd; if constexpr(has_update_v)p->update(),nd->update(); break; } else if(p->right==nd){ if(pp){ if(pp->left==p){ nd->par=pp->par; if(pp->par){ if constexpr(has_middle_v){ if(pp->par->middle==pp)nd->par->middle=nd; else if(pp->par->left==pp)nd->par->left=nd; else if(pp->par->right==pp)nd->par->right=nd; } else{ if(pp->par->left==pp)nd->par->left=nd; else if(pp->par->right==pp)nd->par->right=nd; } } p->right=nd->left; if(p->right)p->right->par=p; pp->left=nd->right; if(pp->left)pp->left->par=pp; nd->left=p; p->par=nd; nd->right=pp; pp->par=nd; if constexpr(has_update_v)pp->update(),p->update(),nd->update(); continue; } else if(pp->right==p){ nd->par=pp->par; if(pp->par){ if constexpr(has_middle_v){ if(pp->par->middle==pp)nd->par->middle=nd; else if(pp->par->left==pp)nd->par->left=nd; else if(pp->par->right==pp)nd->par->right=nd; } else{ if(pp->par->left==pp)nd->par->left=nd; else if(pp->par->right==pp)nd->par->right=nd; } } pp->right=p->left; if(pp->right)pp->right->par=pp; p->right=nd->left; if(p->right)p->right->par=p; nd->left=p; p->par=nd; p->left=pp; pp->par=p; if constexpr(has_update_v)pp->update(),p->update(),nd->update(); continue; } } nd->par=pp; if(pp){ if constexpr(has_middle_v){ if(pp->middle==p)pp->middle=nd; else if(pp->left==p)pp->left=nd; else if(pp->right==p)pp->right=nd; } else{ if(pp->left==p)pp->left=nd; else if(pp->right==p)pp->right=nd; } } p->right=nd->left; if(p->right)p->right->par=p; nd->left=p; p->par=nd; if constexpr(has_update_v)p->update(),nd->update(); break; } else break; } } template [[nodiscard]]T* near(T *nd,decltype(T::key)k){ while(true){ if(kkey){ if constexpr(has_push_v)nd->push(); if(nd->left)nd=nd->left; else{ splay(nd); return nd; } } else if(nd->key)nd->push(); if(nd->right)nd=nd->right; else{ splay(nd); return nd; } } else{ splay(nd); return nd; } } return nullptr; } template [[nodiscard]]T* get_k(T *nd,decltype(T::sz)k){ while(true){ if constexpr(has_push_v)nd->push(); decltype(T::sz) lsz=nd->left?nd->left->sz:0; if(lsz==k)break; else if(kleft; else{ nd=nd->right; k-=1+lsz; } } splay(nd); return nd; } template [[nodiscard]]T* merge(T* l,T *r){ if(!l)return r; if(!r)return l; while(r->left){ if constexpr(has_push_v)r->push(); r=r->left; } if constexpr(has_push_v)r->push(); splay(r); r->left=l; l->par=r; if constexpr(has_update_v)r->update(); return r; } template [[nodiscard]]T* left_most(T*nd){ T nil; T *rnd=&nil; while(nd->left){ if constexpr(has_push_v)nd->push(); T *c=nd->left; if(!c->left){ rnd->left=nd; if constexpr(has_update_v||correct_parent)nd->par=rnd; rnd=rnd->left; nd=c; } else{ if constexpr(has_push_v)c->push(); nd->left=c->right; c->right=nd; if constexpr(has_update_v||correct_parent){ if(nd->left)nd->left->par=nd; nd->par=c; } if constexpr(has_update_v)nd->update(); if constexpr(has_update_v||correct_parent)c->par=rnd; rnd->left=c; nd=c->left; rnd=rnd->left; } } if constexpr(has_push_v)nd->push(); rnd->left=nd->right; nd->right=nil.left; nil.left=nil.right=nullptr; if constexpr(has_update_v||correct_parent){ if(rnd->left)rnd->left->par=rnd; if(nd->right)nd->right->par=nd; nd->par=nullptr; } if constexpr(has_update_v){ if(rnd!=&nil){ while(rnd){ rnd->update(); rnd=rnd->par; } } } return nd; } template [[nodiscard]]T* right_most(T*nd){ T nil; T *lnd=&nil; while(nd->right){ if constexpr(has_push_v)nd->push(); T *c=nd->right; if(!c->right){ lnd->right=nd; if constexpr(has_update_v||correct_parent)nd->par=lnd; lnd=lnd->right; nd=c; } else{ if constexpr(has_push_v)c->push(); nd->right=c->left; c->left=nd; if constexpr(has_update_v||correct_parent){ if(nd->right)nd->right->par=nd; nd->par=c; } if constexpr(has_update_v){ nd->update(); } if constexpr(has_update_v||correct_parent)c->par=lnd; lnd->right=c; nd=c->right; lnd=lnd->right; } } if constexpr(has_push_v)nd->push(); lnd->right=nd->left; nd->left=nil.right; nil.left=nil.right=nullptr; if constexpr(has_update_v||correct_parent){ if(lnd->right)lnd->right->par=lnd; if(nd->left)nd->left->par=nd; nd->par=nullptr; } if constexpr(has_update_v){ if(lnd!=&nil){ while(lnd){ lnd->update(); lnd=lnd->par; } } } return nd; } template void tt_expose(T*nd){ while(true){ splay(nd); if(nd->right){ nd->right->par=nullptr; T *light=new T(); light->vertex=false; light->middle=nd->right; if(nd->middle){ light->left=nd->middle; light->left->par=light; } nd->middle=light; light->par=nd; nd->right->par=light; nd->right=nullptr; if constexpr(has_update_v)light->update(),nd->update(); } if(!nd->par)break; T *pon=nd->par; splay(pon); splay(pon->par); if constexpr(has_push_v)pon->push(); if(pon->par->right){ pon->middle=pon->par->right; pon->middle->par=pon; pon->par->right=nd; nd->par=pon->par; if constexpr(has_update_v)pon->update(),pon->par->update(); } else{ pon->par->right=nd; nd->par=pon->par; T *l=pon->left,*r=pon->right; if(l&&r){ l->par=nullptr; r->par=nullptr; l=merge(l,r); l->par=pon->par; l->par->middle=l; } else if(!l&&!r){ pon->par->middle=nullptr; } else{ if(!l)std::swap(l,r); l->par=pon->par; l->par->middle=l; } if constexpr(has_update_v)nd->par->update(); delete(pon); } } } template void tt_link(T*u,T*v){ tt_expose(u); tt_expose(v); v->reverse(); u->right=v; v->par=u; if constexpr(has_update_v)u->update(); } template void tt_cut(T*u,T*v){ tt_expose(u); u->reverse(); tt_expose(v); v->left=nullptr; u->par=nullptr; if constexpr(has_update_v)v->update(); } template struct csr_array{ private: std::vectorptr; std::vectordat; public: using iterator=typename std::vector::iterator; using const_iterator=typename std::vector::const_iterator; struct csr{ iterator l,r; iterator begin(){return l;} iterator end(){return r;} int size()const{return r-l;} T &operator[](int i)const{return l[i];} }; struct const_csr{ const_iterator l,r; const_iterator begin(){return l;} const_iterator end(){return r;} int size()const{return r-l;} const T &operator[](int i)const{return l[i];} }; csr_array():ptr{0}{} csr_array(int n,const std::vector>&a):ptr(n+1),dat(a.size()){ for(const auto&[k,v]:a)ptr[k]++; for(int i=1;i<=n;i++)ptr[i]+=ptr[i-1]; for(int i=std::ssize(a);i--;)dat[--ptr[a[i].first]]=a[i].second; } explicit csr_array(int n,const std::vector&a):ptr(n+1),dat(a.size()){ static_assert(std::is_same_v); for(const int&x:a)ptr[x]++; for(int i=1;i<=n;i++)ptr[i]+=ptr[i-1]; for(int i=std::ssize(a);i--;)dat[--ptr[a[i]]]=i; } csr operator[](int i){return csr{dat.begin()+ptr[i],dat.begin()+ptr[i+1]};} const_csr operator[](int i)const{return const_csr{dat.begin()+ptr[i],dat.begin()+ptr[i+1]};} iterator begin(){return dat.begin();} iterator end(){return dat.end();} const_iterator begin()const{return dat.begin();} const_iterator end()const{return dat.end();} int size()const{return std::ssize(ptr)-1;} }; template struct Edge{ int from,to; T weight; int index; Edge(int from_,int to_,T weight_=T(),int index_=-1):from(from_),to(to_),weight(weight_),index(index_){} Edge():from(-1),to(-1),weight(),index(-1){} friend std::ostream &operator<<(std::ostream &os,const Edge&e){ os<<'['; os<<"from:"< struct Tree{ int n,r; std::vector>edge; std::vector>g; std::vectorptr; struct tree_range{ using iterator=typename std::vector>::iterator; iterator l,r; iterator begin()const{return l;} iterator end()const{return r;} int size()const{return r-l;} bool empty()const{return !size();} Edge &operator[](int i)const{return l[i];} }; struct const_tree_range{ using iterator=typename std::vector>::const_iterator; iterator l,r; iterator begin()const{return l;} iterator end()const{return r;} int size()const{return r-l;} bool empty()const{return !size();} const Edge &operator[](int i)const{return l[i];} }; explicit Tree(int n_):n(n_){ edge.reserve(n-1); } Tree():n(0){} Tree(int n_,const std::vector>&e,bool dir=false):n(n_),r(-1),edge(e){ if(!dir)build(); else{ std::vectorseen(n,false); ptr.resize(n+1); for(const Edge&i:edge)ptr[i.from]++,ptr[i.to]++,seen[e.to]=true; for(int i=1;i<=n;i++)ptr[i]+=ptr[i-1]; r=std::find(seen.begin(),seen.end(),false)-seen.begin(); assert(ptr[n]==n*2-2); g.resize(ptr[n]); for(const Edge&i:edge)g[--ptr[i.to]]=Edge(i.to,i.from,i.weight,i.index); for(const Edge&i:edge)g[--ptr[i.from]]=i; } } template void read(){ for(int i=0;i>u>>v; if constexpr(index)u--,v--; if constexpr(weighted)std::cin>>w; else w=1; edge.emplace_back(u,v,w,i); } build(); } template void readp(){ ptr.resize(n+1); for(int i=1;i>p; if constexpr(index)p--; edge.emplace_back(p,i,1,i-1); ptr[p]++; ptr[i]++; } for(int i=1;i<=n;i++)ptr[i]+=ptr[i-1]; g.resize(n*2-2); for(auto&&[u,v,w,i]:edge)g[--ptr[v]]=Edge(v,u,w,i); for(int i=0;ipar(n,-1); par[root]=-1; std::queueque; que.push(root); while(!que.empty()){ int x=que.front(); que.pop(); for(int i=ptr[x];i&e=g[i]; if(e.to!=par[x]){ par[e.to]=x; assert(e.indexbfs_order()const{ assert(is_directed()); std::vectorbfs(n); int p=0,q=0; bfs[q++]=root(); while(p&e:(*this)[x])bfs[q++]=e.to; } return bfs; } std::vectordfs_order()const{ assert(is_directed()); std::vectorres; res.reserve(n); std::vectorst(n); int p=0; st[p++]=root(); while(p){ int x=st[--p]; res.push_back(x); p+=(*this)[x].size(); for(const Edge&e:(*this)[x])st[--p]=e.to; p+=(*this)[x].size(); } return res; } std::vectorrbfs_order()const{ std::vectorbfs=bfs_order(); std::reverse(bfs.begin(),bfs.end()); return bfs; } void hld(){ assert(is_directed()); std::vectorsub(n); for(int x:rbfs_order()){ sub[x]=1; int mx=-1; for(Edge&e:(*this)[x]){ sub[x]+=sub[e.to]; if(mx,std::vector>in_out_order(){ assert(is_directed()); std::vectorin(n),out(n); int p=0; auto dfs=[&](auto self,int x)->void { in[x]=p++; for(const Edge&e:(*this)[x]){ self(self,e.to); } out[x]=p; }; dfs(dfs,root()); return std::make_pair(in,out); } std::pair>diameter()const{ assert(!is_directed()); static constexpr T inf=std::numeric_limits::max(); std::vectordst(n,inf); dst[0]=0; std::vectorque(n); int p=0,q=1; que[0]=0; while(p&e:(*this)[x])if(dst[e.to]==inf){ dst[e.to]=dst[x]+e.weight; que[q++]=e.to; } } int u=std::max_element(dst.begin(),dst.end())-dst.begin(); std::fill(dst.begin(),dst.end(),inf); dst[u]=0; p=0,q=1; que[0]=u; while(p&e:(*this)[x])if(dst[e.to]==inf){ dst[e.to]=dst[x]+e.weight; que[q++]=e.to; } } int v=std::max_element(dst.begin(),dst.end())-dst.begin(); T weight=dst[v]; std::vectorres; while(u!=v){ res.push_back(v); for(const Edge&e:(*this)[v])if(dst[e.to]& get_edge(int i)const{return edge[i];} inline int parent(int i)const{return i==r?-1:g[ptr[i+1]-1].to;} inline int root()const{return r;} typename std::vector>::iterator begin(){return edge.begin();} typename std::vector>::iterator end(){return edge.end();} typename std::vector>::const_iterator begin()const{return edge.begin();} typename std::vector>::const_iterator end()const{return edge.end();} }; struct LevelAncestor{ csr_arraybin; std::vectorpos,dep,dfs; LevelAncestor(){} template LevelAncestor(Tree t){ int n=t.size(); pos.resize(n),dep.resize(n); std::vectorbin_v; bin_v.reserve(n); dfs=t.dfs_order(); for(int x:dfs){ pos[x]=bin_v.size(); bin_v.push_back(dep[x]); for(const Edge&e:t[x])dep[e.to]=dep[x]+1; } bin=csr_array(*std::max_element(bin_v.begin(),bin_v.end())+1,bin_v); } int query(int u,int d)const{ if(dep[u] template constexpr std::enable_if_t::digits<=32,int>msb(T n){return n==0?-1:31-__builtin_clz(n);} template constexpr std::enable_if_t<(std::numeric_limits::digits>32),int>msb(T n){return n==0?-1:63-__builtin_clzll(n);} template constexpr std::enable_if_t::digits<=32,int>lsb(T n){return n==0?-1:__builtin_ctz(n);} template constexpr std::enable_if_t<(std::numeric_limits::digits>32),int>lsb(T n){return n==0?-1:__builtin_ctzll(n);} template constexpr std::enable_if_t,T>floor_pow2(T n){return n==0?0:T(1)< constexpr std::enable_if_t,T>ceil_pow2(T n){return n<=1?1:T(1)<<(msb(n-1)+1);} template constexpr T safe_div(T a,T b){return a/b-(a%b&&(a^b)<0);} template constexpr T safe_ceil(T a,T b){return a/b+(a%b&&(a^b)>0);} template struct SparseTable{ using S=typename M::S; private: std::vectordat,prefix,suffix; std::vector>sp; public: SparseTable(){} SparseTable(std::vectora):dat(a){ int n=a.size(); n=(n+(1<d2(n>>L,M::e()); for(int i=0;i<(int)d2.size();i++){ for(int j=0;j<(1<>L);i++){ for(int j=1;j<(1<>L)-1;i>=0;i--){ for(int j=(1<=1;j--)suffix[(i<=j-w;k--)sp[i][k]=M::op(d2[k],sp[i][k+1]); int r=std::min(d2.size(),j+w); for(int k=j+1;k>L,rid=r>>L; if(lid==rid){ S ret=M::e(); for(int i=l;i<=r;i++)ret=M::op(ret,dat[i]); return ret; } else{ lid++; rid--; S mid=M::e(); if(lid==rid)mid=sp[0][lid]; else if(lid; static S op(const S&x,const S&y){return x.first::max(),-1);} }; SparseTablesp; std::vectoridx; public: template LowestCommonAncestor(const Tree&t):idx(t.size()){ assert(t.is_directed()); int r=t.root(); int ord=0; std::vectordep(t.size()); dep[r]=0; std::vector>init(t.size()*2-1); auto dfs=[&](auto&&self,int x)->void { idx[x]=ord; init[ord++]=std::make_pair(dep[x],x); for(const auto&e:t[x]){ dep[e.to]=dep[e.from]+1; self(self,e.to); init[ord++]=std::make_pair(dep[x],x); } }; dfs(dfs,r); sp=SparseTable(init); } LowestCommonAncestor(){} int query(int u,int v)const{ if(u==v)return u; if(idx[u]>idx[v])std::swap(u,v); return sp.prod(idx[u],idx[v]+1).second; } }; struct JumponTree{ private: LowestCommonAncestor lca; LevelAncestor la; public: template JumponTree(Treet){ t.remove_parent(); lca=LowestCommonAncestor(t); la=LevelAncestor(std::move(t)); } int jump(int u,int v,int d)const{ int l=lca.query(u,v); if(la.dep[u]+la.dep[v]-la.dep[l]*2=d)return la.query(u,d); else return la.query(v,la.dep[u]+la.dep[v]-la.dep[l]*2-d); } }; struct Path{ int lb=1e9,rb=1e9; bool contain_b=false; int len=0; int ans=0; int e=0; friend ostream &operator<<(ostream&os,const Path&p){ os<=2){ res.ans++; if(b&&p.b_cnt==1){ res.ans+=p.b; } res.lb=res.rb=0; res.e=0; } else{ res.lb=res.rb=1; res.e=p.b; } // else if(p.b_cnt>=2)res.ans++; return res; } Point add_edge(Path p){ Point res; res.b=p.lb+p.e; res.b_cnt=p.contain_b; res.ans=p.ans; return res; } Path vertex2(bool b){ if(b){ return {0,0,true,1,1,0}; } else{ return {(int)1e9,(int)1e9,false,1,0,0}; } } struct node{ node *left=nullptr,*right=nullptr,*par=nullptr,*middle=nullptr; bool vertex=false; bool b=false; Path dat1,dat1rev; Point dat2; bool rev=false; void reverse(){ rev^=1; swap(dat1,dat1rev); swap(left,right); } void push(){ if(rev){ if(left)left->reverse(); if(right)right->reverse(); rev=false; } } void update(){ if(vertex){ if(middle)dat1=add_vertex(middle->dat2,b); else dat1=vertex2(b); dat1rev=dat1; if(left)dat1=compress(left->dat1,dat1),dat1rev=compress(dat1rev,left->dat1rev); if(right)dat1=compress(dat1,right->dat1),dat1rev=compress(right->dat1rev,dat1rev); } else{ assert(middle); dat2=add_edge(middle->dat1); if(left)dat2=rake(left->dat2,dat2); if(right)dat2=rake(dat2,right->dat2); } } }; void SOLVE(){ int n; cin>>n; vectornds(n); vector>edge(n-1); cin>>edge; edge--; Tree t(n); rep(i,n){ int c; cin>>c; // nds[i].dat1=nds[i].dat1=vertex2(c); nds[i].b=c; nds[i].vertex=true; nds[i].update(); } for(auto [u,v]:edge){ tt_link(&nds[u],&nds[v]); t.add_edge(u,v); } t.build(); JumponTree jt(t); t.remove_parent(); LowestCommonAncestor lca(t); vectordep(n); for(int x:t.bfs_order()){ for(auto e:t[x])dep[e.to]=dep[x]+1; } auto distance=[&](int u,int v)->int { return dep[u]+dep[v]-dep[lca.query(u,v)]*2; }; int q; cin>>q; auto print=[&](){ node*root=&nds[0]; while(root->par)root=root->par; mapmp; auto idx=[&](node *nd)->int { if(!nd)return -1; if(!mp.contains(nd)){ int s=mp.size(); mp[nd]=s; } return mp[nd]; }; rep(i,n)mp[&nds[i]]=i; setvis; auto dfs=[&](auto self,node *nd)->void { if(!nd)return; if(vis.contains(nd))return; vis.insert(nd); debug(idx(nd),idx(nd->left),idx(nd->right),idx(nd->par),idx(nd->middle)); if(idx(nd)dat1); else debug(nd->dat2); self(self,nd->left); self(self,nd->right); self(self,nd->middle); }; debug("------------------------"); dfs(dfs,root); debug("------------------------"); }; while(q--){ int op; cin>>op; if(op==1){ int v; cin>>v; v--; tt_expose(&nds[v]); nds[v].b^=1; nds[v].update(); } else{ int x,y; cin>>x>>y; x--,y--; if(x!=y){ x=jt.jump(x,y,distance(x,y)-1); tt_cut(&nds[x],&nds[y]); } tt_expose(&nds[y]); cout<