#include using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; template using V = vector; template using VV = V>; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); } #define FOR(i, a, b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,N) for(int i=0;i<(int)(N);i++) #define rep1(i,N) for(int i=1;i<=(int)(N);i++) #define fs first #define sc second #define eb emplace_back #define pb eb #define all(x) x.begin(),x.end() template void chmin(T& t, const U& u) { if (t > u) t = u; } template void chmax(T& t, const U& u) { if (t < u) t = u; } // bit op int popcnt(uint x) { return __builtin_popcount(x); } int popcnt(ull x) { return __builtin_popcountll(x); } int bsr(uint x) { return 31 - __builtin_clz(x); } int bsr(ull x) { return 63 - __builtin_clzll(x); } int bsf(uint x) { return __builtin_ctz(x); } int bsf(ull x) { return __builtin_ctzll(x); } template struct lazy_segtree { int _n, size, log; vector d; vector lz; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } void all_apply(int k, F f) { d[k] = mapping(f, d[k]); if (k < size) lz[k] = composition(f, lz[k]); } void push(int k) { all_apply(2 * k, lz[k]); all_apply(2 * k + 1, lz[k]); lz[k] = id(); } lazy_segtree() : lazy_segtree(0) { } explicit lazy_segtree(int n) : lazy_segtree(vector(n, e())) { } explicit lazy_segtree(const vector& v) : _n(int(v.size())) { size = bit_ceil((unsigned int)(_n)); log = countr_zero((unsigned int)size); d = vector(2 * size, e()); lz = vector(size, id()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) { update(i); } } void set(int p, S x) { p += size; for (int i = log; i >= 1; i--) push(p >> i); d[p] = x; for (int i = 1; i <= log; i++) update(p >> i); } S get(int p) { p += size; for (int i = log; i >= 1; i--) push(p >> i); return d[p]; } S prod(int l, int r) { if (l == r) return e(); l += size; r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } S sml = e(), smr = e(); while (l < r) { if (l & 1) sml = op(sml, d[l++]); if (r & 1) smr = op(d[--r], smr); l >>= 1; r >>= 1; } return op(sml, smr); } S all_prod() { return d[1]; } void apply(int p, F f) { p += size; for (int i = log; i >= 1; i--) push(p >> i); d[p] = mapping(f, d[p]); for (int i = 1; i <= log; i++) update(p >> i); } void apply(int l, int r, F f) { if (l == r) return; l += size; r += size; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } { int l2 = l, r2 = r; while (l < r) { if (l & 1) all_apply(l++, f); if (r & 1) all_apply(--r, f); l >>= 1; r >>= 1; } l = l2; r = r2; } for (int i = 1; i <= log; i++) { if (((l >> i) << i) != l) update(l >> i); if (((r >> i) << i) != r) update((r - 1) >> i); } } template int max_right(int l) { return max_right(l, [](S x) { return g(x); }); } template int max_right(int l, G g) { if (l == _n) return _n; l += size; for (int i = log; i >= 1; i--) push(l >> i); S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!g(op(sm, d[l]))) { while (l < size) { push(l); l = (2 * l); if (g(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template int min_left(int r) { return min_left(r, [](S x) { return g(x); }); } template int min_left(int r, G g) { if (r == 0) return 0; r += size; for (int i = log; i >= 1; i--) push((r - 1) >> i); S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!g(op(d[r], sm))) { while (r < size) { push(r); r = (2 * r + 1); if (g(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } }; //頂点vに関する情報はgrp[v]番目のセグ木のpos[v]番目に入れる //g番目のセグ木の長さはgsz[g] struct HL_Decomp{ int N,gord; vector> tr; vector par,dep,sub,grp,pos,gsz,gpar,gdep; HL_Decomp(int N,vector> graph):gord(),par(N),dep(N),sub(N),grp(N),pos(N),gsz(N),gpar(N),gdep(N){ tr=graph; dfs1(0,-1,0); dfs2(0,-1,gord++,0); } int dfs1(int v,int p,int d){ par[v]=p; sub[v]=1; dep[v]=d; for(auto to:tr[v])if(to!=p)sub[v]+=dfs1(to,v,d+1); return sub[v]; } void dfs2(int v,int p,int g,int d){ grp[v]=g; if(gsz[g]==0){ gpar[g]=p; gdep[g]=d; } pos[v]=gsz[g]++; pair si(0,-1); for(auto to:tr[v])if(to!=p)chmax(si,pair(sub[to],to)); for(auto to:tr[v])if(to!=p){ if(to==si.second)dfs2(to,v,g,d); else dfs2(to,v,gord++,d+1); } } int LCA(int a,int b){ if(gdep[grp[a]]>gdep[grp[b]])swap(a,b); while(gdep[grp[a]]dep[b])swap(a,b); return a; } //{g,l,r}はg番目のセグ木のl~rという意味 //lrなら[r:l)の逆順 //edge=trueの場合はlcaを含まない区間を返す vector> query(int a,int b,bool edge=false){ vector> l,r; while(gdep[grp[a]]>gdep[grp[b]]){ l.emplace_back(grp[a],pos[a]+1,0); a=gpar[grp[a]]; } while(gdep[grp[a]]dep[b])l.emplace_back(grp[a],pos[a]+1,pos[b]+e); else if(dep[a]>N>>Q; vector C(N); for(int i=0;i>C[i]; } vector> graph(N); for(int i=0;i>a>>b; a-=1;b-=1; graph[a].push_back(b); graph[b].push_back(a); } HL_Decomp HL(N,graph); vector> LST(N); for(int g=0;g(HL.gsz[g]); } for(int x=0;x>T>>x>>y; x-=1; if(T==1){ for(auto [g,l,r]:HL.query(x,0)){ LST[g].apply(min(l,r),max(l,r),y); } } else{ int ans=LST[HL.grp[x]].prod(HL.pos[x],HL.pos[x]+1); cout<