/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include #include #ifndef SOLUTION_COMMON_H #include using namespace std; using ll = long long; using PI = pair; template using V = vector; using VI = V; #define _1 first #define _2 second #ifdef MY_DEBUG # define DEBUG(x) x #else # define DEBUG(x) #endif template inline void debug(T &A) { DEBUG( for (const auto &a : A) { cerr << a << " "; } cerr << '\n'; ) } template inline void debug_with_format(T &A, Func f) { DEBUG( for (const auto &a : A) { cerr << f(a) << " "; } cerr << '\n'; ) } template inline void debug_dim2(T &A) { DEBUG( for (const auto &as : A) { debug(as); } ) } template inline void debug(const char *format, Args const &... args) { DEBUG( fprintf(stderr, format, args ...); cerr << '\n'; ) } template string format(const string &fmt, Args ... args) { size_t len = snprintf(nullptr, 0, fmt.c_str(), args ...); vector buf(len + 1); snprintf(&buf[0], len + 1, fmt.c_str(), args ...); return string(&buf[0], &buf[0] + len); } template string fmtP(pair a) { stringstream ss; ss << "(" << a._1 << "," << a._2 << ")"; return ss.str(); } #define SOLUTION_COMMON_H #endif //SOLUTION_COMMON_H class BIT { public: int N; V bit; BIT(int n): N(n + 1), bit(N) {} void add(int i, ll x) { i++; while(i < N) { bit[i] += x; i += i & -i; } } ll query(int i) { ll ans = 0ll; while(i) { ans += bit[i]; i -= i & -i; } return ans; } }; const int MOD = 1000000007; class D { public: void solve(std::istream& in, std::ostream& out) { int n; in >> n; V> g(n); for (int i = 0; i < n - 1; ++i) { int u, v, w; in >> u >> v >> w; g[u].emplace_back(v, w); g[v].emplace_back(u, w); } V dp(n); VI tour; V pos(n); VI depth(n); int mx_depth = 0; function init = [&](int v, int p, int weight) { pos[v]._1 = (int)tour.size(); tour.push_back(v); if (p != -1) { dp[v] = dp[p] + weight; depth[v] = depth[p] + 1; mx_depth = max(mx_depth, depth[v]); } for (const auto &e : g[v]) { if (e._1 != p) init(e._1, v, e._2); } pos[v]._2 = (int)tour.size(); tour.push_back(v); }; init(0, -1, 0); debug(depth); debug("%d", mx_depth); // debug(tour); // DEBUG( // for (int i = 0; i < n; ++i) { // cerr << "(" << pos[i]._1 << "," << pos[i]._2 << ") "; // } // ) BIT bit(2 * n); BIT cum(2 * n); int q; in >> q; for (int i = 0; i < q; ++i) { int tpe; in >> tpe; if (tpe == 1) { int a, x; in >> a >> x; bit.add(pos[a]._1, x); bit.add(pos[a]._2, -x); cum.add(pos[a]._1, ((ll)(mx_depth - depth[a])) * x); cum.add(pos[a]._2, -((ll)(mx_depth - depth[a])) * x); } else { int b; in >> b; debug("%d %d", b, pos[b]._1); ll v = cum.query(pos[b]._1) - bit.query(pos[b]._1) * (mx_depth - depth[b]) + dp[b]; out << v << '\n'; } } } }; int main() { D solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }