func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 3e5 + 10;   template <typename value_t>   class fenwick {    public:     fenwick(int n) {       memset(c, 0, sizeof c);       this->n = n;     }     void add(int i, value_t x) {       while (i <= n) {         c[i] += x;         i += Lowbit(i);       }     }     value_t sum(int x) {       value_t sum = 0;       while (x > 0) {         sum += c[x];         x -= Lowbit(x);       }       return sum;     }     value_t sum(int x1, int x2) { return sum(x2) - sum(x1 - 1); }       private:     value_t c[MAXN];     int n;     inline int Lowbit(int x) { return x & (-x); }   };   class lfs {    public:     lfs(int N) {       memset(head, -1, sizeof head);       ecnt = 0;       n = N;     }     void adde(int from, int to, int w) {       e[ecnt].to = to;       e[ecnt].w = w;       e[ecnt].next = head[from];       head[from] = ecnt++;     }     void addde(int a, int b, int w) {       adde(a, b, w);       adde(b, a, w);     }     void solve() {       memset(ans, 0, sizeof ans);       arr = new fenwick<long long>(n);       dfs(1, 0, 1);     }     vector<pair<int, int>> opr[MAXN];     long long ans[MAXN];       protected:     struct Edge {       int to, next, w;     } e[MAXN * 2];     int head[MAXN];     int ecnt;     int n;     fenwick<long long>* arr;     void dfs(int u, int fa, int dep) {       for (auto& i : opr[u]) {         arr->add(dep, i.second);         arr->add(dep + i.first + 1, -i.second);       }       ans[u] = arr->sum(dep);       for (int i = head[u]; i != -1; i = e[i].next) {         int v = e[i].to;         if (v != fa) dfs(v, u, dep + 1);       }       for (auto& i : opr[u]) {         arr->add(dep, -i.second);         arr->add(dep + i.first + 1, i.second);       }     }   };   template <typename T = int>   inline T read() {     T X = 0, w = 0;     char ch = 0;     while (!isdigit(ch)) {       w |= ch ==  - ;       ch = getchar();     }     while (isdigit(ch)) {       X = (X << 3) + (X << 1) + (ch ^ 48);       ch = getchar();     }     return w ? -X : X;   }   int main() {     int n = read();     lfs* tree = new lfs(n);     for (int i = 1; i < n; i++) {       tree->addde(read(), read(), 1);     }     int m = read();     for (int i = 1; i <= m; i++) {       int u = read();       int d = read();       int x = read();       tree->opr[u].push_back(make_pair(d, x));     }     tree->solve();     for (int i = 1; i <= n; i++) {       cout << tree->ans[i] <<    ;     }     cout << endl;   }   