func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m, K;   vector<int> G[700005], W[700005], I[700005];   long long int ptr[700005];   long long int ans[700005];   int dis[700005], rem[700005], ulta[700005], vis[700005], tim = 0, lev[700005];   int mx = 0;   vector<int> jinish[700005];   void dfs(int u, int l) {     lev[u] = l;     mx = max(mx, l);     vis[u] = 1;     dis[u] = ++tim;     ulta[tim] = u;     jinish[l].push_back(tim);     for (int v : G[u]) {       if (!vis[v]) {         dfs(v, l + 1);       }     }     rem[u] = tim;   }   void dfs2(int u) {     vis[u] = 1;     for (auto v : G[u]) {       if (!vis[v]) {         ans[v] += ans[u];         dfs2(v);       }     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d %d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     dfs(1, 1);     scanf( %d , &m);     while (m--) {       int u, d, x;       scanf( %d %d %d , &u, &d, &x);       ans[u] += x;       int go = min(lev[u] + d + 1, mx + 1);       int in = lower_bound(jinish[go].begin(), jinish[go].end(), dis[u]) -                jinish[go].begin();       if (in < jinish[go].size()) ptr[jinish[go][in]] += x;       int inn = upper_bound(jinish[go].begin(), jinish[go].end(), rem[u]) -                 jinish[go].begin();       if (inn < jinish[go].size()) ptr[jinish[go][inn]] -= x;     }     for (int i = 1; i <= mx; i++) {       for (int j = 1; j < jinish[i].size(); j++) {         ptr[jinish[i][j]] += ptr[jinish[i][j - 1]];       }     }     for (int i = 1; i <= mx; i++) {       for (int j = 0; j < jinish[i].size(); j++) {         ans[ulta[jinish[i][j]]] -= ptr[jinish[i][j]];       }     }     memset(vis, 0, sizeof vis);     dfs2(1);     bool ff = false;     for (int u = 1; u <= n; u++) {       if (ff) printf(   );       ff = true;       printf( %lld , ans[u]);     }     cout << endl;   }   