func_code_string: #include <bits/stdc++.h>   int B = 400;   using namespace std;   const long long inf = 1e8;   int MOD = 1e9 + 7;   const int mxn = 300010;   const int N = 1000005;   const double pi = 3.14159;   int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};   int dy[] = {1, 0, -1, 0, -1, 1, 1, -1};   int n, d, k;   vector<int> g[mxn];   vector<pair<int, int> > q[mxn];   long long add[mxn];   long long ans[mxn];   void dfs(int v, int p = -1, int d = 1, long long cur = 0) {     for (auto i : q[v]) {       int d_ = i.first, val = i.second;       cur += (long long)val;       int tot = min(d + d_ + 1, mxn);       add[tot] -= (long long)val;     }     cur += add[d];     ans[v] = cur;     for (auto i : g[v]) {       if (i == p) continue;       dfs(i, v, d + 1, cur);     }     for (auto i : q[v]) {       int d_ = i.first, val = i.second;       int tot = min(d + d_ + 1, mxn);       add[tot] += (long long)val;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       g[u].push_back(v), g[v].push_back(u);     }     int qn;     cin >> qn;     while (qn--) {       int n, d, val;       cin >> n >> d >> val;       q[n].push_back({d, val});     }     dfs(1);     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;   }   