func_code_string: #include <bits/stdc++.h>   using namespace std;   int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};   int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};   const double PI = acos(-1.0);   const double EPS = 1e-6;   const int MOD = (int)1e9 + 7;   const int maxn = (int)3e5 + 10;   const int LOGN = 20;   struct Upd {     int x, d;     Upd(int xx, int dd) {       x = xx;       d = dd;     }   };   int n;   long long c[maxn];   vector<Upd> upd[maxn];   vector<int> g[maxn];   int dep[maxn];   long long BIT[maxn];   void add(int pos, int val) {     while (pos <= n) {       BIT[pos] += val;       pos += (pos & -pos);     }   }   long long sum(int pos) {     long long sum = 0;     while (pos > 0) {       sum += BIT[pos];       pos -= (pos & -pos);     }     return sum;   }   void dfs_cal(int u, int p) {     dep[u] = dep[p] + 1;     for (Upd up : upd[u]) {       add(1, up.x);       add(dep[u] + up.d, -up.x);     }     c[u] += sum(dep[u]);     for (int v : g[u])       if (v != p) {         dfs_cal(v, u);       }     for (Upd up : upd[u]) {       add(1, -up.x);       add(dep[u] + up.d, up.x);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     for (int i = 1; i <= (n - 1); i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v);       g[v].push_back(u);     }     int q;     cin >> q;     for (int i = 1; i <= (q); i++) {       int v, d, x;       cin >> v >> d >> x;       ++d;       d = min(d, n);       upd[v].push_back(Upd(x, d));     }     dfs_cal(1, 0);     for (int i = 1; i <= (n); i++) cout << c[i] <<    ;     return 0;   }   