#include using namespace std; #define int long long #define rep(i,n) for(int i=0;i<(n);i++) #define pb push_back #define all(v) (v).begin(),(v).end() #define fi first #define se second typedef vectorvint; typedef pairpint; typedef vectorvpint; templateinline void chmin(A &a,B b){if(a>b)a=b;} templateinline void chmax(A &a,B b){if(a struct WeightedTree{ struct Edge{ int to; W cost; Edge(int to,W cost):to(to),cost(cost){} }; int V; vector>G; vector>par; vectordep,sz,head; vectortin,tout; vectordist; WeightedTree(int V):V(V),G(V),par(lg,vector(V)),sz(V),dep(V),head(V),dist(V),tin(V),tout(V){} void addEdge(int a,int b,W c=W(1)){ G[a].push_back(Edge(b,c)); G[b].push_back(Edge(a,c)); } void dfs(int v,int p,int d,W c){ par[0][v]=p; dep[v]=d; sz[v]=1; dist[v]=c; for(auto &e:G[v]){ if(e.to==p)continue; dfs(e.to,v,d+1,c+e.cost); sz[v]+=sz[e.to]; if(G[v][0].to==p||sz[e.to]>sz[G[v][0].to])swap(G[v][0],e); } } void dfs_hld(int v,int &tt){ tin[v]=tt++; for(auto &e:G[v]){ if(e.to==par[0][v])continue; head[e.to]=(e.to==G[v][0].to)?head[v]:e.to; dfs_hld(e.to,tt); } tout[v]=tt; } void init(){ dfs(0,-1,0,W(0)); int tt=0; dfs_hld(0,tt); for(int i=0;i+1=N-1!!!!! int getLCA(int u,int v){ if(dep[u]>i&1)u=par[i][u]; if(u==v)return u; for(int i=lg-1;i>=0;i--)if(par[i][u]!=par[i][v])u=par[i][u],v=par[i][v]; return par[0][v]; } int getLength(int a,int b=0){ int l=getLCA(a,b); return dep[a]+dep[b]-2*dep[l]; } W getDistance(int a,int b=0){ int l=getLCA(a,b); return dist[a]+dist[b]-2*dist[l]; } int getPar(int v,int k=0){ return par[k][v]; } int getDepth(int v){ return dep[v]; } int getIn(int v){ return tin[v]; } int getOut(int v){ return tout[v]; } }; /* 0-indexed add(k,x): a[k]+=x sum(k): sum(a[0,k]) space:O(N) time:O(logN) per query */ struct BinaryIndexedTree{ int n; vectordat; BinaryIndexedTree(int n=0):n(n){ dat.resize(n+1); } void add(int k,int x){ for(k++;k<=n;k+=k&-k)dat[k]+=x; } int sum(int k){ int ret=0; for(k++;k;k-=k&-k)ret+=dat[k]; return ret; } }; signed main(){ int N;scanf("%lld",&N); WeightedTreeT(N); rep(i,N-1){ int a,b,c; scanf("%lld%lld%lld",&a,&b,&c); T.addEdge(a,b,c); } T.init(); BinaryIndexedTree bit0(111111),bit1(111111); int Q;scanf("%lld",&Q); while(Q--){ int t;scanf("%lld",&t); if(t==1){ int a,x; scanf("%lld%lld",&a,&x); bit1.add(T.getIn(a),x);bit1.add(T.getOut(a),-x); bit0.add(T.getIn(a),-T.getDepth(a)*x);bit0.add(T.getOut(a),T.getDepth(a)*x); } else{ int b;scanf("%lld",&b); int ans=T.getDistance(b); ans+=bit0.sum(T.getIn(b)); ans+=bit1.sum(T.getIn(b))*T.getDepth(b); printf("%lld\n",ans); } } return 0; }