#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include using namespace std; #define pass (void)0 #define INF (1<<30)-1 #define INFLL (1LL<<60)-1 #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--) #define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define repr2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int)(x).size()) #define YesNo(cond) cout << ((cond) ? "Yes\n" : "No\n") #define YESNO(cond) cout << ((cond) ? "YES\n" : "NO\n") using ll = long long; using pii = pair; using pll = pair; using vi = vector; using vl = vector; using vvi = vector; using vvl = vector; template void print(const T& value) { cout << value << "\n"; } template void print(const vector& vec) { for (auto& v : vec) cout << v << " "; cout << "\n"; } template void input(vector& vec) { for (auto& v : vec) cin >> v; }; template bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; } template bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; } #include using namespace atcoder; using mint = modint998244353; using vm = vector; struct LCA { int V; int LOG; vector> parent; vector depth; vector d; LCA(const vector>>& G, int root = 0) { V = (int)G.size(); LOG = 1; while ((1 << LOG) < V) LOG++; parent.assign(LOG, vector(V, -1)); depth.assign(V, -1); d.assign(V, -1); bfs(G, root); for (int i = 0; i + 1 < LOG; i++) { for (int v = 0; v < V; v++) { if (parent[i][v] != -1) { parent[i + 1][v] = parent[i][ parent[i][v] ]; } } } } void bfs(const vector>>& G, int root) { queue q; depth[root] = 0; d[root] = 0; q.push(root); while (!q.empty()) { int u = q.front(); q.pop(); for (auto [v, w] : G[u]) { if (depth[v] == -1) { d[v] = d[u]+w; depth[v] = depth[u] + 1; parent[0][v] = u; q.push(v); } } } } int lca(int a, int b) const { if (depth[a] < depth[b]) swap(a, b); int diff = depth[a] - depth[b]; for (int i = 0; i < LOG; i++) { if (diff & (1 << i)) { a = parent[i][a]; } } if (a == b) return a; for (int i = LOG - 1; i >= 0; i--) { if (parent[i][a] != parent[i][b]) { a = parent[i][a]; b = parent[i][b]; } } return parent[0][a]; } int dist(int a, int b) const { int c = lca(a, b); return d[a] + d[b] - 2 * d[c]; } bool is_ancestor(int u, int v) const { return lca(u, v) == u; } int kth_ancestor(int v, int k) const { for (int i = 0; i < LOG; i++) { if (k & (1 << i)) { v = parent[i][v]; if (v == -1) break; } } return v; } int jump(int u, int v) const { if (u == v) return u; int c = lca(u, v); if (c == u) { return kth_ancestor(v, dist(u, v) - 1); } else { return parent[0][u]; } } int jump_k(int u, int v, int k) const { int d = dist(u, v); if (d <= k) return v; int c = lca(u, v); int du = depth[u] - depth[c]; if (k <= du) { return kth_ancestor(u, k); } else { return kth_ancestor(v, d - k); } } bool on_path(int u, int v, int x) const { return dist(u, x) + dist(x, v) == dist(u, v); } pair create_path(int u, int v, int x) const { if (on_path(u, v, x)) return {u, v}; if (on_path(u, x, v)) return {u, x}; if (on_path(v, x, u)) return {v, x}; return {-1, -1}; } }; vi IN; vi OUT; vector>> G; vi sign; int dfs(int n, int time) { IN[n] = time; if (n != 0) sign.push_back(1); for (auto [v, _] : G[n]) { time = dfs(v, time+1); } OUT[n] = time; if (n != 0) sign.push_back(-1); return time+1; } struct Node { ll value; int sign; }; Node op(Node left, Node right) { return {left.value+right.value, left.sign+right.sign}; } Node e() { return {0, 0}; } Node mapping(ll top, Node bottom) { bottom.value += top*bottom.sign; return bottom; } ll composition(ll top, ll bottom) { return bottom+top; } ll id() { return 0; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); int N; cin >> N; G.assign(N, vector> ()); rep (_, N-1) { int u, v; ll w; cin >> u >> v >> w; G[u].push_back({v, w}); } LCA lca(G); IN.assign(N, -1); OUT.assign(N, -1); dfs(0, 0); vector def; rep (i, sz(sign)) { def.push_back({0, sign[i]}); } lazy_segtree seg(def); int Q; cin >> Q; while (Q--) { int q; cin >> q; if (q == 1) { int a; ll x; cin >> a >> x; if (IN[a] == OUT[a]) continue; seg.apply(IN[a], OUT[a], x); } else { int b; cin >> b; if (b != 0) { print(lca.dist(0, b)+seg.prod(0, IN[b]).value); } else { print(0); } } } }