#include using namespace std; typedef long long ll; typedef pair l_l; typedef pair i_i; template inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; typedef vector> Graph; template< typename G > struct DoublingLowestCommonAncestor { const int LOG; vector< int > dep; const G &g; vector< vector< int > > table; DoublingLowestCommonAncestor(const G &g) : g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size())) { table.assign(LOG, vector< int >(g.size(), -1)); } void dfs(int idx, int par, int d) { table[0][idx] = par; dep[idx] = d; for(auto &to : g[idx]) { if(to != par) dfs(to, idx, d + 1); } } void build() { dfs(0, -1, 0); for(int k = 0; k + 1 < LOG; k++) { for(int i = 0; i < table[k].size(); i++) { if(table[k][i] == -1) table[k + 1][i] = -1; else table[k + 1][i] = table[k][table[k][i]]; } } } int query(int u, int v) { if(dep[u] > dep[v]) swap(u, v); for(int i = LOG - 1; i >= 0; i--) { if(((dep[v] - dep[u]) >> i) & 1) v = table[i][v]; } if(u == v) return u; for(int i = LOG - 1; i >= 0; i--) { if(table[i][u] != table[i][v]) { u = table[i][u]; v = table[i][v]; } } return table[0][u]; } int P(int u, int d) { int digit = 0; while(d > 0) { if(d & (1 << digit)) { u = table[digit][u]; d &= ~(1 << digit); } digit++; } return u; } }; vector pathes[100500]; vector children[100500]; ll cost[100500], nowcost[100500]; void DFS(int now, ll nowval) { nowval += nowcost[now]; cost[now] += nowval; nowcost[now] = 0; for(int &to : children[now]) DFS(to, nowval); } ll parent[100050]; void initialize(int now, int from) { for(auto to : pathes[now]) { if(to == from) continue; children[now].push_back(to); parent[to] = now; initialize(to, now); } } int ope, a, b; ll x; vector query; const int B = 2000; ll u[100050], v[100050], w[100050]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; parent[0] = -1; Graph G(N); for(int i = 0; i <= N - 2; i++) { cin >> u[i] >> v[i] >> w[i]; G[u[i]].push_back(v[i]); G[v[i]].push_back(u[i]); pathes[u[i]].push_back(v[i]); pathes[v[i]].push_back(u[i]); } initialize(0, -1); for(int i = 0; i <= N - 2; i++) { if(parent[u[i]] == v[i]) swap(u[i], v[i]); nowcost[v[i]] += w[i]; } DFS(0, 0); DoublingLowestCommonAncestor LCA(G); LCA.build(); ll Q; cin >> Q; while(Q--) { cin >> ope; if(ope == 1) { cin >> a >> x; query.emplace_back(a, x); nowcost[a] += x; } else { cin >> b; ll ans = cost[b]; for(l_l now : query) { if(LCA.query(now.first, b) == now.first) { ans += now.second * (LCA.dep[b] - LCA.dep[now.first]); } } cout << ans << "\n"; } if((Q + 1) % B == 0) { query.clear(); DFS(0, 0); } } return 0; }