func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = INT_MAX;   const long long INFL = LLONG_MAX;   const long double pi = acos(-1);   class SumSegTree {    private:     vector<long long> sum, lazy;     int N;     void check_index(int i) {       if (i < 0 || N <= i) {         throw  index out of bound ;       }     }       public:     SumSegTree(int N) {       this->N = 1;       while (this->N < N) this->N <<= 1;       this->sum.resize(this->N << 1);       this->lazy.resize(this->N << 1);     }     long long get_sum(int l, int r) {       check_index(l);       check_index(r);       return get_sum(l, r, 0, N - 1, 1);     }     void add(int l, int r, int val) {       check_index(l);       check_index(r);       add(l, r, val, 0, N - 1, 1);     }     void delegate(int a, int b, int n) {       sum[n] += (b - a + 1) * lazy[n];       if (a < b) {         lazy[n * 2] += lazy[n];         lazy[n * 2 + 1] += lazy[n];       }       lazy[n] = 0;     }     long long get_sum(int l, int r, int a, int b, int n) {       if (b < l || r < a) return 0;       if (lazy[n] != 0) delegate(a, b, n);       if (l <= a && b <= r) return sum[n];       int m = (a + b) / 2;       return get_sum(l, r, a, m, n * 2) + get_sum(l, r, m + 1, b, n * 2 + 1);     }     void add(int l, int r, long long val, int a, int b, int n) {       if (b < l || r < a) return;       if (l <= a && b <= r) {         if (a == b)           sum[n] += val;         else           lazy[n] += val;       } else {         int m = (a + b) / 2;         if (lazy[n] != 0) delegate(a, b, n);         sum[n] += (min(b, r) - max(a, l) + 1) * val;         add(l, r, val, a, m, n * 2);         add(l, r, val, m + 1, b, n * 2 + 1);       }     }   };   int N, M;   vector<int> adj[300100];   vector<pair<int, long long> > query[300100];   SumSegTree segt(300005);   long long ans[300100];   void dfs(int u, int prev, int h) {     for (int(i) = 0; (i) < (int((query[u]).size())); (i)++) {       int dist = query[u][i].first;       long long value = query[u][i].second;       segt.add(h, min(N, h + dist), value);     }     ans[u] = segt.get_sum(h, h);     for (int(i) = 0; (i) < (int((adj[u]).size())); (i)++) {       int v = adj[u][i];       if (v == prev) continue;       dfs(v, u, h + 1);     }     for (int(i) = 0; (i) < (int((query[u]).size())); (i)++) {       int dist = query[u][i].first;       long long value = query[u][i].second;       segt.add(h, min(N, h + dist), -value);     }   }   int main() {     ios_base::sync_with_stdio(0);     cout.precision(15);     cout << fixed;     cout.tie(0);     cin.tie(0);     cin >> N;     for (int(i) = 1; (i) <= (N - 1); (i)++) {       int a, b;       cin >> a >> b;       adj[a].push_back(b);       adj[b].push_back(a);     }     cin >> M;     for (int(i) = 1; (i) <= (M); (i)++) {       int v, d;       long long x;       cin >> v >> d >> x;       query[v].push_back(make_pair(d, x));     }     dfs(1, 0, 0);     for (int(i) = 1; (i) <= (N); (i)++)       cout << ans[i] << (i + 1 <= N ?     :   n );   }   