func_code_string: #include <bits/stdc++.h>   using namespace std;   const double EPS = 1e-8;   const int mod = 1e9 + 7;   const int N = 1e6 + 10;   const long long INF = 1e18;   long long power(long long x, long long y) {     long long t = 1;     while (y > 0) {       if (y % 2)         y -= 1, t = t * x % mod;       else         y /= 2, x = x * x % mod;     }     return t;   }   long long val[N];   vector<pair<long long, long long> > G[N];   int vk[N];   set<pair<long long, long long> > S[N];   int ans[N];   int tl = 0;   void merge(int &p, int nw, long long cs) {     if (S[nw].size() == 0) return;     set<pair<long long, long long> >::iterator it = S[nw].end();     vector<pair<long long, long long> > z;     while (1) {       it--;       if ((*it).first > cs) {         z.push_back(*it);       } else         break;       if (it == S[nw].begin()) break;     }     for (int i = 0; i < z.size(); ++i) S[nw].erase(z[i]);     if (p == -1) {       p = nw;       return;     }     if (S[p].size() < S[nw].size()) swap(p, nw);     it = S[nw].begin();     while (it != S[nw].end()) {       S[p].insert(*it);       it++;     }   }   int dfs1(int v, long long c) {     int my = -1;     for (int i = 0; i < G[v].size(); ++i) {       int x = dfs1(G[v][i].first, G[v][i].second + c);       merge(my, x, c);     }     if (my == -1) my = tl++;     ans[v] = S[my].size();     S[my].insert(make_pair(c - val[v], v));     return my;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %lld , &val[i]);     for (int i = 0; i < n - 1; ++i) {       long long x, y;       scanf( %lld%lld , &x, &y);       x--;       G[x].push_back(make_pair(i + 1, y));     }     dfs1(0, 0);     for (int i = 0; i < n; ++i) printf( %d  , ans[i]);     printf(  n );     return 0;   }   