#include using namespace std; using ll = long long; using pll = pair; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); const ll MOD1000000007 = 1000000007; const ll MOD998244353 = 998244353; const ll MOD[3] = {999727999, 1070777777, 1000000007}; const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; template struct edge{ int from, to; T cost; int id; edge(){} edge(int to, T cost=1) : from(-1), to(to), cost(cost){} edge(int to, T cost, int id) : from(-1), to(to), cost(cost), id(id){} edge(int from, int to, T cost, int id) : from(from), to(to), cost(cost), id(id){} }; template struct redge{ int from, to; T cap, cost; int rev; redge(int to, T cap, T cost=(T)(1)) : from(-1), to(to), cap(cap), cost(cost){} redge(int to, T cap, T cost, int rev) : from(-1), to(to), cap(cap), cost(cost), rev(rev){} }; template using Edges = vector>; template using weighted_graph = vector>; template using tree = vector>; using unweighted_graph = vector>; template using residual_graph = vector>>; template struct vertex_add_path_sum{ struct segtree{ int n; vector dat; segtree(){}; segtree(int n_){ n = 1; while(n < n_) n*=2; dat.resize(2*n, 0); } void update(int k, W a){ k += n-1; dat[k] += a; while(k > 0){ k = (k-1)/2; dat[k] = dat[2*k+1]+dat[2*k+2]; } } // sum of [a, b) W query(int a, int b){return query_sub(a, b, 0, 0, n);} W query_sub(int a, int b, int k, int l, int r){ if(r <= a || b <= l){ return 0; }else if(a <= l && r <= b){ return dat[k]; }else{ W vl = query_sub(a, b, 2*k+1, l, (l+r)/2); W vr = query_sub(a, b, 2*k+2, (l+r)/2, r); return vl+vr; } } } seg; struct lowest_common_ancestor{ int root = 0; int n; int log_n = 1; vector> par; vector depth; lowest_common_ancestor(){} lowest_common_ancestor(tree &T, int root = 0) : root(root){ n = (int)T.size(); while((1 << log_n) < n) log_n++; par.resize(log_n, vector(n, -1)); depth.resize(n, 0); init(T); } void init(tree &T){ function dfs = [&](int v, int p){ par[0][v] = p; for(edge e : T[v]) if(e.to!=p){ depth[e.to] = depth[v]+1; dfs(e.to, v); } }; dfs(root, -1); for(int k=0; k+1> k & 1) u = par[k][u]; if(u == v) return u; for(int k=log_n-1; k>=0; k--){ if(par[k][u] != par[k][v]){ u = par[k][u]; v = par[k][v]; } } return par[0][u]; } } lca; int n; vector par; vector pos; vector depth; vector path_top; vertex_add_path_sum(tree &T, int root = 0){ n = (int)T.size(); par.resize(n, 0); pos.resize(n, 0); depth.resize(n, 0); path_top.resize(n, -1); init(T, root); } void init(tree &T, int root){ vector siz(n, 1); //par, siz, depthを計算 function dfs1 = [&](int v, int p){ par[v] = p; for(edge e : T[v]) if(e.to!=p){ depth[e.to] = depth[v]+1; dfs1(e.to, v); siz[v] += siz[e.to]; } }; dfs1(root, -1); //heavy-light decomposition int cnt = 0; function dfs2 = [&](int v, int p, int a){ pos[v] = cnt++; path_top[v] = a; int M = 0; int ch = -1; for(edge e : T[v]) if(e.to!=p){ if(siz[e.to] > M){ M = siz[e.to]; ch = e.to; } } if(ch!=-1) dfs2(ch, v, a); for(edge e : T[v]) if(e.to!=p && e.to!=ch) dfs2(e.to, v, e.to); }; dfs2(root, -1, root); seg = segtree(n); lca = lowest_common_ancestor(T, root); } vector> hld_query(int u, int v){ vector> ret; int r = lca.query(u, v); while(path_top[u] != path_top[r]){ ret.push_back({pos[path_top[u]], pos[u]}); u = par[path_top[u]]; } while(path_top[v] != path_top[r]){ ret.push_back({pos[path_top[v]], pos[v]}); v = par[path_top[v]]; } ret.push_back({min(pos[u], pos[v]), max(pos[u], pos[v])}); return ret; } void update(int v, W x){ seg.update(pos[v], x); } W query(int u, int v){ vector> hld = hld_query(u, v); W ans = 0; for(pair p : hld) ans += seg.query(p.fi, p.se+1); return ans; } }; void solve(){ int n, q; cin >> n >> q; vector a(n+1, 0); for(int i=0; i> a[i]; tree T(n+1); T[0].push_back(edge(n)); T[n].push_back(edge(0)); for(int i=0; i> u >> v; u--; v--; T[u].push_back(edge(v)); T[v].push_back(edge(u)); } vertex_add_path_sum hld(T, n); //初期化 function dfs = [&](int v, int p){ ll sum = 0; for(edge e : T[v]) if(e.to != p){ sum += a[e.to]; dfs(e.to, v); } hld.update(v, sum); }; dfs(n, -1); while(q--){ int type; cin >> type; if(type==0){ int v, x; cin >> v >> x; v--; hld.update(hld.par[v], x); a[v] += x; } if(type==1){ int u, v; cin >> u >> v; u--; v--; int r = hld.lca.query(u, v); cout << hld.query(u, v) + a[r] + a[hld.par[r]] << '\n'; } } } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int T=1; //cin >> T; while(T--) solve(); }