#include #define LLI long long int #define FOR(v, a, b) for(LLI v = (a); v < (b); ++v) #define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v) #define REP(v, n) FOR(v, 0, n) #define REPE(v, n) FORE(v, 0, n) #define REV(v, a, b) for(LLI v = (a); v >= (b); --v) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it) #define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it) #define EXIST(c,x) ((c).find(x) != (c).end()) #define fst first #define snd second #define popcount __builtin_popcount #define UNIQ(v) (v).erase(unique(ALL(v)), (v).end()) #define bit(i) (1LL<<(i)) #ifdef DEBUG #include #else #define dump(...) ((void)0) #endif #define gcd __gcd using namespace std; template constexpr T lcm(T m, T n){return m/gcd(m,n)*n;} template void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost< istream& operator>>(istream &is, vector &v){for(auto &a : v) is >> a; return is;} template bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);} template bool chmax(T &a, const U &b){return (a void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);} struct Init{ Init(){ cin.tie(0); ios::sync_with_stdio(false); } }init; template class Edge{ public: int from,to; Cost cost; Edge() {} Edge(int to, Cost cost): to(to), cost(cost){} Edge(int from, int to, Cost cost): from(from), to(to), cost(cost){} Edge rev() const {return Edge(to,from,cost);} friend ostream& operator<<(ostream &os, const Edge &e){ os << "(FROM: " << e.from << "," << "TO: " << e.to << "," << "COST: " << e.cost << ")"; return os; } }; template using Graph = vector>>; template using Tree = vector>>; template void add_edge(C &g, int from, int to, T w){ g[from].push_back(Edge(from, to, w)); } template void add_undirected(C &g, int a, int b, T w){ g[a].push_back(Edge(a, b, w)); g[b].push_back(Edge(b, a, w)); } template class HLDecomposition{ Tree tree; int n; vector sub, // subtree size par, // parent id head, // chain head id id, // id[original id] = hld id rid, // rid[hld id] = original id next, // next node in a chain end; // int dfs_sub(int cur, int p){ par[cur] = p; int t = 0; for(auto &e : tree[cur]){ if(e.to == p) continue; sub[cur] += dfs_sub(e.to, cur); if(sub[e.to] > t){ t = sub[e.to]; next[cur] = e.to; swap(e, tree[cur][0]); } } return sub[cur]; } void dfs_build(int cur, int &i){ id[cur] = i; rid[i] = cur; ++i; for(auto &e : tree[cur]){ if(e.to == par[cur]) continue; head[e.to] = (e.to == tree[cur][0].to ? head[cur] : e.to); dfs_build(e.to, i); } end[cur] = i; } public: HLDecomposition(const Tree &tree): tree(tree), n(tree.size()), sub(n,1), par(n,-1), head(n), id(n), rid(n), next(n,-1), end(n, -1){ dfs_sub(0, -1); int i=0; dfs_build(0, i); } void path_query_vertex(int x, int y, const function &f){ while(1){ if(id[x] > id[y]) swap(x, y); f(max(id[head[y]], id[x]), id[y]+1); if(head[x] == head[y]) return; y = par[head[y]]; } } void path_query_edge(int x, int y, const function &f){ while(1){ if(id[x] > id[y]) swap(x, y); if(head[x] == head[y]){ if(x != y) f(id[x]+1, id[y]+1); return; } f(id[head[y]], id[y]+1); y = par[head[y]]; } } void subtree_query_edge(int x, const function &f){ f(id[x]+1, end[x]); } void subtree_query_vertex(int x, const function &f){ f(id[x], end[x]); } int get_edge_id(int u, int v){ // 辺に対応するid if(par[u] == v){ return id[u]; }else if(par[v] == u){ return id[v]; } return -1; } int parent(int x){return par[x];}; int lca(int u, int v){ while(1){ if(id[u] > id[v]) swap(u, v); if(head[u] == head[v]) return u; v = par[head[v]]; } } int get_id(int x){ return id[x]; } }; template class SegmentTreeRangeAddQueryRangeSumQuery{ int size; vector vec1; vector vec2; T e1; U e2; inline void propagate(int i, int l){ if(vec2[i] == e2) return; if(i < size/2){ vec2[i*2+1] = vec2[i] + vec2[i*2+1]; vec2[i*2+2] = vec2[i] + vec2[i*2+2]; } vec1[i] = vec1[i] + vec2[i] * l; vec2[i] = e2; } inline T update_aux(int i, int l, int r, int s, int t, const U &x){ propagate(i,r-l); if(r <= s || t <= l) return vec1[i]; else if(s <= l && r <= t){ vec2[i] = vec2[i] + x; propagate(i,r-l); return vec1[i]; } else return vec1[i] = update_aux(i*2+1,l,(l+r)/2,s,t,x) + update_aux(i*2+2,(l+r)/2,r,s,t,x); } inline T query_aux(int i, int l, int r, int x, int y){ propagate(i,r-l); if(r <= x || y <= l) return e1; else if(x <= l && r <= y) return vec1[i]; else return query_aux(i*2+1,l,(l+r)/2,x,y) + query_aux(i*2+2,(l+r)/2,r,x,y); } public: SegmentTreeRangeAddQueryRangeSumQuery(int n, const T &e1, const U &e2): e1(e1), e2(e2){ size = 1; while(size(size,e1); vec2 = vector(size,e2); } inline void update(int s, int t, const U &x){ update_aux(0,0,size/2+1,s,t,x); } inline T get(int x, int y){ return query_aux(0,0,size/2+1,x,y); } inline void update_at(int s, const U &x){ update(s,s+1,x); } }; int main(){ int N; cin >> N; Tree tree(N); REP(i,N-1){ int u, v; cin >> u >> v; LLI w; cin >> w; add_undirected(tree, u, v, w); } HLDecomposition hld(tree); SegmentTreeRangeAddQueryRangeSumQuery seg(N, 0, 0); REP(i,N){ for(auto &e : tree[i]){ if(e.from < e.to){ int k = hld.get_edge_id(e.from, e.to); seg.update_at(k, e.cost); } } } int Q; cin >> Q; REP(_,Q){ int c; cin >> c; if(c == 1){ int a, x; cin >> a >> x; hld.subtree_query_edge(a, [&](int i, int j){seg.update(i,j,x);}); }else{ int b; cin >> b; LLI ans = 0; hld.path_query_edge(0, b, [&](int i, int j){ans += seg.get(i,j);}); cout << ans << endl; } } return 0; }