#include #include #include #include #include #include #include #include #include #include #include #include #define vll vector #define vvv vector #define vvi vector > #define vvl vector > #define vv(a, b, c, d) vector >(a, vector(b, c)) #define vvvl(a, b, c, d) vector(a, vvl(b, vll (c, d))); #define rep(c, a, b) for(ll c=a;c dat; segtree(){}; segtree(ll N, ll num){ INIT = num; while(M0) k = (k-1)/2, dat[k] = dat[k*2+1] + dat[k*2+2]; } ll query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){ if(r==-1) r = M; if(b==-1) b = M; if(r<=a || b<=l) return INIT; if(a<=l && r<=b) return dat[k]; ll A = query(a, b, k*2+1, l, (l+r)/2); ll B = query(a, b, k*2+2, (l+r)/2, r); return A + B; } }; struct LazySegmentTree { private: int n; vector node, lazy; segtree sg; public: LazySegmentTree(){}; LazySegmentTree(vector v, segtree s) { sg = s; int sz = (int)v.size(); n = 1; while(n < sz) n *= 2; node.resize(2*n-1); lazy.resize(2*n-1, 0); for(int i=0; i=0; i--) node[i] = node[i*2+1] + node[i*2+2]; } void eval(int k, int l, int r) { if(lazy[k] != 0) { node[k] += (lazy[k]*sg.dat[k]); if(r - l > 1) { lazy[2*k+1] += lazy[k]; lazy[2*k+2] += lazy[k]; } lazy[k] = 0; } } void add(int a, int b, ll x, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b) { lazy[k] += x; eval(k, l, r); } else { add(a, b, x, 2*k+1, l, (l+r)/2); add(a, b, x, 2*k+2, (l+r)/2, r); node[k] = node[2*k+1] + node[2*k+2]; } } ll getsum(int a, int b, int k=0, int l=0, int r=-1) { if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return 0; if(a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2*k+1, l, (l+r)/2); ll vr = getsum(a, b, 2*k+2, (l+r)/2, r); return vl + vr; } }; struct EulerTour{ ll N, root = 0, o = 0; vector> G; LazySegmentTree seg; segtree table; vll begin, end, tour, depth; vvl parent; EulerTour(vector> g){ N = g.size(); G = g; begin.resize(N+1); end.resize(N+1); depth.resize(N+1); parent.resize(30, vll(N+1)); table = segtree(2*N+1, 0); init_(); seg = LazySegmentTree(vll(2*N+1, 0), table); } void init_(){ tour_init(root, -1); lca_init(); table_init(); } void tour_init(ll now, ll from){ begin[now] = o; tour.push_back(now); o++; for(int i=0;idepth[tour[i+1]]) table.update(-1, i); else table.update(1, i); } } void dfs(int v, int p, int d){ parent[0][v] = p, depth[v] = d; for(int i=0;idepth[v]) swap(u, v); for(int k=0;k<30;k++)if((depth[v]-depth[u])>>k & 1) v = parent[k][v]; if(u==v) return u; for(int k=30-1;k>=0;k--){ if(parent[k][u] != parent[k][v]){ u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } // aの部分木の各辺にx加算 // パスa,bの値取得 void update(ll a, ll x){ seg.add(begin[a], end[a], x); } ll query(ll a, ll b){ ll l = lca(a, b); ll A = seg.getsum(begin[root], begin[a]); ll B = seg.getsum(begin[root], begin[b]); ll C = seg.getsum(begin[root], begin[l]); return A + B - 2*C; } }; struct edge{ll to, cost;}; vll d(100001, 0); vector> T(100001); void DFS(ll now, ll from, ll c){ d[now] = c; for(int i=0;i> n; vvl G = vv(n, 0, 0, ll); re(i, n-1){ std::cin >> a >> b >> c; G[a].push_back(b); G[b].push_back(a); T[a].push_back(edge{b, c}); T[b].push_back(edge{a, c}); } DFS(0, -1, 0); EulerTour e(G); ll q;std::cin >> q; re(i, q){ std::cin >> a >> b; if(a==1) { std::cin >> c; e.update(b, c); }else std::cout << e.query(0, b) + d[b] << '\n'; } return 0; }