#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
//# define M_PI           3.14159265358979323846264338327950288

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
VL visited;
VL dist;
vector< vector< II > > g;
VL pos, from, to;
LL t, n;
VL arr;
const LL maxn = (LL)(2e5 + 1);
LL a[maxn];
void calc(int s, int d){
	visited[s] = 1;
	dist[s] = d;
	pos[s] = ++t;
	a[pos[s]] = d;
	from[s] = t;
	to[s] = t;
	for(auto u : g[s]){
		if(!visited[u.F]){
			calc(u.F, d + u.S);
			to[s] = max(to[s], to[u.F]);
		}
	}
}
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================
const LL MAX =(LL) 1e15;
struct wavelet_tree{
	#define vi vector<LL>
	#define pb push_back
	LL lo, hi;
	wavelet_tree *l, *r;
	vi b;

	//nos are in range [x,y]
	//array indices are [from, to)
	wavelet_tree(LL *from, LL *to, LL x, LL y){
		lo = x, hi = y;
		if(lo == hi or from >= to) return;
		LL mid = (lo+hi)/2;
		auto f = [mid](LL x){
			return x <= mid;
		};
		b.reserve(to-from+1);
		b.pb(0);
		for(auto it = from; it != to; it++)
			b.pb(b.back() + f(*it));
		//see how lambda function is used here
		auto pivot = stable_partition(from, to, f);
		l = new wavelet_tree(from, pivot, lo, mid);
		r = new wavelet_tree(pivot, to, mid+1, hi);
	}

	//kth smallest element in [l, r]
	LL kth(LL l, LL r, LL k){
		if(l > r) return 0;
		if(lo == hi) return lo;
		LL inLeft = b[r] - b[l-1];
		LL lb = b[l-1]; //amt of nos in first (l-1) nos that go in left
		LL rb = b[r]; //amt of nos in first (r) nos that go in left
		if(k <= inLeft) return this->l->kth(lb+1, rb , k);
		return this->r->kth(l-lb, r-rb, k-inLeft);
	}

	//count of nos in [l, r] Less than or equal to k
	LL LTE(LL l, LL r, LL k) {
		if(l > r or k < lo) return 0;
		if(hi <= k) return r - l + 1;
		LL lb = b[l-1], rb = b[r];
		return this->l->LTE(lb+1, rb, k) + this->r->LTE(l-lb, r-rb, k);
	}

	//count of nos in [l, r] equal to k
	LL count(LL l, LL r, LL k) {
		if(l > r or k < lo or k > hi) return 0;
		if(lo == hi) return r - l + 1;
		LL lb = b[l-1], rb = b[r], mid = (lo+hi)/2;
		if(k <= mid) return this->l->count(lb+1, rb, k);
		return this->r->count(l-lb, r-rb, k);
	}
	~wavelet_tree(){
		delete l;
		delete r;
	}
};
int main() {
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
	cin>>n;
	arr.resize(n);
	rep(i,0,n)
	cin>>arr[i];
	LL p,w;
	g.resize(n);
	pos.resize(n+1);from.resize(n+1);to.resize(n+1);
	visited.resize(n,0);
	dist.resize(n,0);
	rep(i,1,n){
		cin>>p>>w;
		p--;
		g[p].PB(MP(i, w));
	}

	t = 0;
	calc(0, 0);
	// cout<<"a : \n";
	// rep(i,1,n+1){
	// 	cout<<a[i]<<" ";
	// }
	// cout<<"\n";
	// cout<<"from : \n";
	// rep(i,0,n){
	// 	cout<<from[i]<<" ";
	// }
	// cout<<"\n";
	// cout<<"to : \n";
	// rep(i,0,n){
	// 	cout<<to[i]<<" ";
	// }
	// cout<<"\n ---------------\n";
	wavelet_tree tr(a+1, a+n+1, 1, MAX);
	VL ans(n);
	rep(i,0,n){
		// cout<<from[i]<<" "<<to[i]<<" "<<arr[i] + dist[i]<<"\n";
		LL res = tr.LTE(from[i], to[i], arr[i] + dist[i]);
		ans[i] = res;
	}
	rep(i,0,n){
		cout<<ans[i] - 1<<" ";
	}
  	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define eps 1e-9
#define all(a)   a.begin(),a.end()
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define sz size()
#define rd(inp) scanf("%lld",&inp)
#define rd2(inp1, inp2) scanf("%lld %lld",&inp1, &inp2)
#define rl(inp) scanf("%d",&inp)
#define pf(out) printf("%lld\n", out);

const long long linf = 1e18+5;
const int mod = (int) 1e9 + 7;
const int inf = 1e9;

ll read(){
	bool minus = false;
	ll result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch-'0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result*10 + (ch - '0');
	}
	if (minus){
		return -result;
	}
	else{
		return result;
	}
}

ll fpow(ll base,ll power){
	ll result = 1;
	while (power > 0){
		if (power%2 == 1) result=(result*base);
  		base = (base*base);
  		power /= 2;
  	}
	return result;
}

#define maxn 200010

vector<ll> arr;
ll a[maxn], d[maxn], dp[maxn], par[maxn], n;
vector<pair<ll,ll> > adj[maxn];

void dfs(ll node){
	arr.pb(node);
	ll lo, hi, mid;
	lo = 0, hi = arr.sz - 1;
	ll ans = arr.sz - 1;
	while ( lo<=hi ){
		mid = (hi + lo) / 2;
		if ( d[node] - d[arr[mid]] <= a[node] ){
			ans = mid;
			hi = mid-1;
		}
		else lo = mid+1;
	}

	dp[par[node]] ++;
	dp[par[arr[ans]]] --;

	for ( ll j = 0 ; j < adj[node].sz ; j ++ ){
		d[adj[node][j].F] = d[node] + adj[node][j].S;
		dfs(adj[node][j].F);
	}
	arr.pop_back();
}

void go(ll v){
	for ( ll j = 0 ; j < adj[v].sz ; j ++ ){
		go(adj[v][j].F);
		dp[v] += dp[adj[v][j].F];
	}
}

int main(){
	n = read();
	ll i;
	for ( i = 1 ; i <= n ; i ++ ){
		a[i] = read();
	}
	for ( i = 2 ; i <= n ; i ++ ){
		ll p, w;
		p = read();
		w = read();
		adj[p].pb(mp(i, w));
		par[i] = p;
	}
	dfs(1);
	go(1);
	for ( i = 1 ; i <= n ; i ++ ) printf("%lld ", dp[i]);

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define bcount __builtin_popcount
#define mbit __builtin_ctz
#define pb push_back
using namespace std;
using namespace __gnu_pbds;
typedef tree<long,null_type,less<long>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const long long mod=1e9+7;
typedef long long ll;

ll cost[200010][20];
vector <ll> g[200010];
vector<ll> a(200010,0);
vector<ll> p(200010,0);
vector<ll> d(200010,0);
vector<ll> arr(200010,0);
ll n;
ll up[200010][20];
vector<ll> w(200010,0);

void dfs(ll v) {
 	up[v][0]=p[v];
 	cost[v][0]=w[v];
 	for(int i=1;i<=18;i++){
 	    up[v][i]=up[up[v][i-1]][i-1];
 	    cost[v][i]=cost[up[v][i-1]][i-1]+cost[v][i-1];
 	}
 	for(int i=0; i<g[v].size();i++){
 	 	ll to=g[v][i];
 	 	if(to==p[v]) continue;
 	 	dfs(to);
 	 	d[v]+=d[to];
 	 	d[v]-=arr[v];
 	 	arr[v]=0;
 	}
 	ll x=v;
 	ll cur=0;
 	for(ll i=18;i>=0;i--){
 	 	if(up[x][i]>0 && cur+cost[x][i]<=a[v]){
 	 		cur+=cost[x][i];
 	 		x=up[x][i];
 	 	}
 	}
 	arr[up[x][0]]++;
 	d[v]++;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for (int i=1;i<=n;i++)
		cin>>a[i];
	for (int i=2;i<=n;i++) {
	 	cin>>p[i]>>w[i];
	 	g[p[i]].pb(i);
	}
	dfs(1);

	for (int i = 1; i <= n; i++)
		cout<<d[i]-1<<" ";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MAX = 2 * 1e5 + 47;

vector < pair <int, int> > g[MAX];

vector <int> a(MAX);

vector <int> dist(MAX, 1e9);

int djk(int start){
    int c = -1;
    set < pair <int, int> > s;
    s.insert({0, start});
    while (s.size()){
        pair <int, int> v = *s.begin();
        s.erase(s.begin());
        int u = v.second;
        int cost = v.first;
        if (cost > dist[u]) continue;
        dist[u] = cost;
        if (cost <= a[u]) c++;
        for (int i = 0; i < g[u].size(); i++){
            int next = g[u][i].first;
            int pluss = g[u][i].second;
            s.insert({pluss + cost, next});
        }
    }
    return c;
}

int main(){
    Draganov47();
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
        g[i].push_back({pr, cost});
    }
    for (int i = 0; i < n; i++) cout << djk(i) << ' ';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MAX = 2 * 1e5 + 47;

vector < pair <int, int> > g[MAX];

vector <ll> a(MAX);

int n;

vector <ll> dist(MAX, 2e18);

int djk(int start){
    vector <int> sum(n);
    set < pair <ll, ll> > s;
    s.insert({0, start});
    while (s.size()){
        pair <ll, ll> v = *s.begin();
        s.erase(s.begin());
        ll u = v.second;
        ll cost = v.first;
        if (cost <= a[u]) sum[u] = 1;
        dist[u] = min(cost, dist[u]);
        for (int i = 0; i < g[u].size(); i++){
            int next = g[u][i].first;
            int pluss = g[u][i].second;
            if (dist[next] == 2e18){
                s.insert({pluss + cost, next});
            }
        }
    }
    int c = -1;
    for (int i = 0; i < n; i++) c += sum[i];
    return c;
}

int main(){
    Draganov47();
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
    }
    for (int i = 0; i < n; i++) cout << djk(i) << ' ';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MAX = 2 * 1e5 + 47;

vector < pair <int, int> > g[MAX];

vector <ll> a(MAX);

vector <ll> dist(MAX, 2e18);

int djk(int start){
    int c = -1;
    set < pair <ll, ll> > s;
    s.insert({0, start});
    while (s.size()){
        pair <int, int> v = *s.begin();
        s.erase(s.begin());
        ll u = v.second;
        ll cost = v.first;
        if (cost > dist[u]) continue;
        dist[u] = cost;
        if (cost <= a[u]) c++;
        for (int i = 0; i < g[u].size(); i++){
            int next = g[u][i].first;
            int pluss = g[u][i].second;
            s.insert({pluss + cost, next});
        }
    }
    return c;
}

int main(){
    Draganov47();
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
    }
    for (int i = 0; i < n; i++) cout << djk(i) << ' ';
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

using namespace std;

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n;

vector <ll> a;

vector <ll> dist;

vector <int> sum;

vector <vector <pair <int, int>>> g;

void read(){
    cin >> n;
    a.resize(n);
    g.resize(n);
    dist.resize(n);
    sum.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
    }
}

vector <int> pr, open, close;

void upd_in(int u){
    pr.insert(pr.begin(), u);
    open.insert(open.begin(), 0);
    close.insert(close.begin(), 0);
}

void upd_out(int u){
    sum[u] += open[0];
    if (open.size() > 1) open[1] += open[0], open[1] -= close[0];
    open.erase(open.begin());
    close.erase(close.begin());
    pr.erase(pr.begin());
}

int dfs(int u, ll d){
    upd_in(u);
    dist[u] = d;
    int l = 0, r = pr.size();
    while (l + 1 < r){
        int m = (l + r) >> 1;
        if (dist[u] - dist[pr[m]] > a[u]) r = m;
        else l = m;
    }
    if (pr.size() && dist[u] - dist[pr[l]] <= a[u] && l > 0){
        open[1]++;
        close[l]++;
    }
    for (int j = 0; j < g[u].size(); j++) {
        dfs(g[u][j].first, d + g[u][j].second);
    }
    upd_out(u);
}

void solve(){
    dfs(0, 0);
    for (int i = 0; i < n; i++) cout << sum[i] << " ";
}

int main(){
    Draganov47();
    read();
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

using namespace std;

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int n;

vector <ll> a;

vector <ll> dist;

vector <int> sum;

vector <vector <pair <int, int>>> g;

void read(){
    cin >> n;
    a.resize(n);
    g.resize(n);
    dist.resize(n);
    sum.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
    }
}

deque <int> pr, open, close;

void upd_in(int u){
    pr.push_front(u);
    open.push_front(0);
    close.push_front(0);
}

void upd_out(int u){
    sum[u] += open[0];
    if (open.size() > 1) open[1] += open[0], open[1] -= close[0];
    pr.pop_front();
    open.pop_front();
    close.pop_front();
}

int dfs(int u, ll d){
    upd_in(u);
    dist[u] = d;
    int l = 0, r = pr.size();
    while (l + 1 < r){
        int m = (l + r) >> 1;
        if (dist[u] - dist[pr[m]] > a[u]) r = m;
        else l = m;
    }
    if (pr.size() && dist[u] - dist[pr[l]] <= a[u] && l > 0){
        open[1]++;
        close[l]++;
    }
    for (int j = 0; j < g[u].size(); j++) {
        dfs(g[u][j].first, d + g[u][j].second);
    }
    upd_out(u);
}

void solve(){
    dfs(0, 0);
    for (int i = 0; i < n; i++) cout << sum[i] << " ";
}

int main(){
    Draganov47();
    read();
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MAX = 2 * 1e5 + 47;

vector < pair <int, int> > g[MAX];

vector <ll> a(MAX);

int n;

vector <ll> dist(MAX, 2e18);

int djk(int start){
    vector <int> sum(n);
    set < pair <ll, ll> > s;
    s.insert({0, start});
    while (s.size()){
        pair <ll, ll> v = *s.begin();
        s.erase(s.begin());
        ll u = v.second;
        ll cost = v.first;
        if (cost > dist[u]) continue;
        if (cost <= a[u]) sum[u] = 1;
        dist[u] = cost;
        for (int i = 0; i < g[u].size(); i++){
            int next = g[u][i].first;
            int pluss = g[u][i].second;
            s.insert({pluss + cost, next});
        }
    }
    int c = -1;
    for (int i = 0; i < n; i++) c += sum[i];
    return c;
}

int main(){
    Draganov47();
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
    }
    for (int i = 0; i < n; i++) cout << djk(i) << ' ';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MAX = 2 * 1e5 + 47;

vector < pair <int, int> > g[MAX];

vector <int> a(MAX);

vector <int> dist(MAX, 1e9);

int djk(int start){
    int c = -1;
    set < pair <int, int> > s;
    s.insert({0, start});
    while (s.size()){
        pair <int, int> v = *s.begin();
        s.erase(s.begin());
        int u = v.second;
        int cost = v.first;
        if (cost > dist[u]) continue;
        dist[u] = cost;
        if (cost <= a[u]) c++;
        for (int i = 0; i < g[u].size(); i++){
            int next = g[u][i].first;
            int pluss = g[u][i].second;
            s.insert({pluss + cost, next});
        }
    }
    return c;
}

int main(){
    Draganov47();
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
    }
    for (int i = 0; i < n; i++) cout << djk(i) << ' ';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MAX = 2 * 1e5 + 47;

vector < pair <int, int> > g[MAX];

vector <ll> a(MAX);

int n, sum = 0;

bitset <MAX> used;

void dfs(int u, ll dist){
    used[u] = 1;
    if (dist <= a[u]) sum++;
    for (int j = 0; j < g[u].size(); j++){
        int next = g[u][j].first;
        if (!used[next]) dfs(next, dist + g[u][j].second);
    }
}

int main(){
    Draganov47();
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
    }
    for (int i = 0; i < n; i++){
        used.reset();
        sum = 0;
        dfs(i, 0);
        cout << sum - 1 << ' ';
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MAX = 2 * 1e5 + 47;

vector < pair <int, int> > g[MAX];

vector <ll> a(MAX);

int n;

vector <ll> dist(MAX, 2e18);

int djk(int start){
    vector <int> sum(n);
    set < pair <ll, ll> > s;
    s.insert({0, start});
    while (s.size()){
        pair <int, int> v = *s.begin();
        s.erase(s.begin());
        ll u = v.second;
        ll cost = v.first;
        if (cost > dist[u]) continue;
        if (cost <= a[u]) sum[u] = 1;
        dist[u] = cost;
        for (int i = 0; i < g[u].size(); i++){
            int next = g[u][i].first;
            int pluss = g[u][i].second;
            s.insert({pluss + cost, next});
        }
    }
    int c = -1;
    for (int i = 0; i < n; i++) c += sum[i];
    return c;
}

int main(){
    Draganov47();
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
    }
    for (int i = 0; i < n; i++) cout << djk(i) << ' ';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MAX = 2 * 1e5 + 47;

vector < pair <int, int> > g[MAX];

vector <ll> a(MAX);

int n;

vector <ll> dist(MAX, 2e18);

int djk(int start){
    vector <int> sum(n);
    set < pair <ll, ll> > s;
    s.insert({0, start});
    while (s.size()){
        pair <ll, ll> v = *s.begin();
        s.erase(s.begin());
        ll u = v.second;
        ll cost = v.first;
        if (cost <= a[u]) sum[u] = 1;
        dist[u] = min(cost, dist[u]);
        for (int i = 0; i < g[u].size(); i++){
            int next = g[u][i].first;
            int pluss = g[u][i].second;
            s.insert({pluss + cost, next});
        }
    }
    int c = -1;
    for (int i = 0; i < n; i++) c += sum[i];
    return c;
}

int main(){
    Draganov47();
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
    }
    for (int i = 0; i < n; i++) cout << djk(i) << ' ';
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ll long long
#define ld long double

void Draganov47(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int MAX = 2 * 1e5 + 47;

vector < pair <int, int> > g[MAX];

vector <ll> a(MAX);

vector <ll> dist(MAX, 2e18);

int djk(int start){
    int c = -1;
    set < pair <int, int> > s;
    s.insert({0, start});
    while (s.size()){
        pair <int, int> v = *s.begin();
        s.erase(s.begin());
        ll u = v.second;
        ll cost = v.first;
        if (cost > dist[u]) continue;
        dist[u] = cost;
        if (cost <= a[u]) c++;
        for (int i = 0; i < g[u].size(); i++){
            int next = g[u][i].first;
            int pluss = g[u][i].second;
            s.insert({pluss + cost, next});
        }
    }
    return c;
}

int main(){
    Draganov47();
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 1; i < n; i++){
        int pr, cost;
        cin >> pr >> cost;
        pr--;
        g[pr].push_back({i, cost});
    }
    for (int i = 0; i < n; i++) cout << djk(i) << ' ';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int par[20][N + 1], lvl[N + 1], val[N + 1];
int arr[N + 1];
long long dist[N + 1];
vector<pair<int, int> > adj[N + 1];
void dfs(int s, int p) {
  par[0][s] = p;
  for (auto nbr : adj[s]) {
    if (nbr.first != p) {
      lvl[nbr.first] = lvl[s] + 1;
      dist[nbr.first] = dist[s] + nbr.second;
      dfs(nbr.first, s);
    }
  }
}
void dfs2(int s, int p) {
  for (auto nbr : adj[s]) {
    if (nbr.first != p) {
      dfs2(nbr.first, s);
      val[s] += val[nbr.first];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("intt.txt", "r", stdin);
  freopen("outt.txt", "w", stdout);
#endif

  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> arr[i];
  for (int i = 2; i <= n; i++) {
    int u, w;
    cin >> u >> w;
    adj[u].push_back({i, w});
    adj[i].push_back({u, w});
  }
  adj[0].push_back({1, 1});
  dfs(0, -1);
  for (int d = 1; d < 20; d++) {
    for (int i = 0; i <= n; i++) {
      int mid = par[d - 1][i];
      if (mid == -1)
        par[d][i] = -1;
      else
        par[d][i] = par[d - 1][mid];
    }
  }
  for (int i = 1; i <= n; i++) {
    int curr = i;
    for (int j = 19; j >= 0; j--) {
      if (par[j][curr] != -1 && arr[i] >= dist[i] - dist[par[j][curr]]) {
        curr = par[j][curr];
      }
    }
    if (!curr)
      curr = 1;
    val[par[0][i]]++;
    val[par[0][curr]]--;
  }
  dfs2(0, -1);
  for (int i = 1; i <= n; i++)
    cout << val[i] << ' ';
  return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define SPEED ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define RFOR(i, b, a) for (ll i = b; i >= a; --i)
#define ALL(x) x.begin(), x.end()
#define DEBUG(args...) { string _s = #args; replace(ALL(_s), ' ', '\0');\
replace(ALL(_s), ',', ' ');\
stringstream _ss(_s); istream_iterator<string> _it(_ss); _debug(_it, args);}
#define endl "\n"
#define F first
#define S second
#define pb(x) push_back(x)a
#define mp(x, y) make_pair(x, y)

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void _debug(istream_iterator<string>) {}
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T first, Args... args) {
    cerr << ">> " << *it << " : " << first << endl; _debug(++it, args...);
}
template <typename T1, typename T2>
inline ostream& operator << (ostream& out, const pair<T1, T2>& p) {
    return out << "(" << p.F << ", " << p.S << ")";
}
template<typename T>
inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty()) return out << "[]";
    else { out << '['; for (auto& e : v) { out << e << ", "; } return out << "\b\b]"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const set<T>& s) {
    if (s.empty()) return out << "{}";
    else { out << '{'; for (auto& e : s) { out << e << ", "; } return out << "\b\b}"; }
}
template<typename T>
inline ostream& operator << (ostream& out, const unordered_set<T>& s) {
    return out << set<T>(ALL(s));
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const map<T1, T2>& m) {
    if (m.empty()) return out << "{}";
    out << '{'; for (auto& p : m) { out << p << ", "; } return out << "\b\b}";
}
template<typename T1, typename T2>
inline ostream& operator << (ostream& out, const unordered_map<T1, T2>& m) {
    return out << map<T1, T2>(ALL(m));
}
template<typename T>
inline ostream& operator << (ostream& out, const ordered_set<T>& s) {
    return out << set<T>(ALL(s));
}

typedef long long ll;
typedef long double ld;
typedef vector<long long> vll;
typedef pair<ll, ll> pll;
typedef vector<pair<ll, ll>> vpll;
typedef unordered_map<ll, ll> STll;
/**********************************************************************************
* SEGMENT TREE WITH DEBUGGER (WITH SAMPLE OPERATION)   @author: manishjoshi394
**********************************************************************************/
class SegmentTree {
    vector<ll> _tree;
    int n;

    int left(int v) const {
        return 2 * v;
    }
    int right(int v) const {
        return 2 * v + 1;
    }
    template<typename T>
    void build(int v, int l, int r, const vector<T>& arr) {
        if (l == r) {
            _tree[v] = arr[l];
        } else {
            int mid = l + (r - l) / 2;
            build(left(v), l, mid, arr);
            build(right(v), mid + 1, r, arr);

            _tree[v] = _tree[left(v)] + _tree[right(v)];
        }
    }
    void update(int v, int l, int r, int pos, ll new_val) {
        if (l == r) {
            _tree[v] = new_val;
        } else {
            int mid = l + (r - l) / 2;

            if (pos <= mid)
                update(left(v), l, mid, pos, new_val);
            else
                update(right(v), mid + 1, r, pos, new_val);

            _tree[v] = _tree[left(v)] + _tree[right(v)];
        }
    }
    ll query(int v, int l, int r, int ql, int qr) const {
        if (ql > qr)
            return 0;
        if (l == ql && r == qr) return _tree[v];
        int mid = l + (r - l) / 2;
        return query(left(v), l, mid, ql, min(mid, qr)) +
                   query(right(v), mid + 1, r, max(mid + 1, ql), qr);
    }
public:
    template<typename T>
    SegmentTree(const vector<T>& arr) {
        n = arr.size();
        _tree.resize(4 * n);
        build(1, 0, n - 1, arr);
    }
    SegmentTree(int _n, ll _init = 0) : SegmentTree(vector<ll>(_n, _init)) {}

    ll rmaxq(int l, int r) const {
        return query(1, 0, n - 1, l, r);
    }

    void update(int pos, ll new_val) {
        update(1, 0, n - 1, pos, new_val);
    }

    int size() const {
        return n;
    }
};
inline ostream& operator << (ostream& out, SegmentTree& SegTree) {
    vector<ll> vals;
    for (int i = 0; i < SegTree.size(); ++i) {
        vals.push_back(SegTree.rmaxq(i, i));
    }
    return out << vals;
}
/************************************** MAIN PROGRAM ********************************************/
const int MAX = 2e5 + 1;
const bool PROCESS = true;
const bool ADD = false;

vector<pair<int, ll>> adj[MAX];
ll depth[MAX];
const int root = 0;
int tin[MAX];
int sz[MAX];
int t = 0;

void dfs(int v = root, int u = root, ll deep = 0) {
    tin[v] = t++;
    depth[v] = deep;
    sz[v] = 1;
    for (auto [w, weight] : adj[v]) {
        if (w == u) continue;
        dfs(w, v, deep + weight);
        sz[v] += sz[w];
    }
}

struct event {
    int type;
    int v;
    ll value;

    bool operator < (const event &other) {
        if (value == other.value) return type < other.type;
        return value < other.value;
    }
};

int main()
{
   // freopen("input.txt", "r", stdin);
    SPEED
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &e : a) {
        cin >> e;
    }
    for (int i = 1; i < n; ++i) {
        int j; ll w;
        cin >> j >> w;
        j--;
        adj[i].push_back({j, w});
        adj[j].push_back({i, w});
    }
    dfs();

    vector<event> events;
    for (int v = 0; v < n; ++v) {
           // DEBUG(depth[v])
        events.push_back({ADD, v, depth[v] - a[v]});
        events.push_back({PROCESS, v, depth[v]});
    }
    sort(ALL(events));

    SegmentTree st(n);
    vector<int> ans(n);
    for (auto [type, v, value] : events) {
        if (type == ADD) {
            st.update(tin[v], 1);
          //  DEBUG(v)
            //DEBUG(st)
        } else {
            int l = tin[v] + 1;
            int r = tin[v] + sz[v] - 1;
           // DEBUG("\n", v, st)
            ans[v] = st.rmaxq(l, r);
        }

    }
  //  DEBUG(ans)
    for (auto e : ans) {
        cout << e << ' ';
    }
}
/************************************** END OF PROGRAM ******************************************/
/** Stuff you should look for:
 * int overflow, array bounds, over-counting
 * special cases (n=1?), set/unordered_set TLE, multi-set/set error
 * do something instead of nothing and stay organized
 */


#include<bits/stdc++.h>

#define int long long int
#define mp make_pair
using namespace std;

const int N = 1e5+10;
vector <pair <int, int> > v[N];
int no[N];
const int LG = log2(N) + 1;
int time1 = 0;
int P[LG][N];
int tin[N], tout[N], level[N];
int n;
int dist[N];
int value[N];
int fans[N];
bool visited[N];

void init()
{
    for (int i = 1; i <= n; ++i) {
        visited[i] = false;
    }
}

void dfs(int node, int par, int lvl,int d) {
    visited[node] = true;
    P[0][node] = par;
    level[node] = lvl;
    dist[node] = dist[par] + d;
    for (int i = 0 ; i<v[node].size();i++) {
        if(visited[v[node][i].first] == false) {
            dfs(v[node][i].first, node, lvl + 1, v[node][i].second);
        }
    }
}

void precompute() {
    for (int i = 1; i < LG; i++)
        for (int j = 1; j <= n; j++)
            if (P[i - 1][j])
                P[i][j] = P[i - 1][P[i - 1][j]];
}

int parent(int level, int node) {
    while (level) {
        int i = 0;
        while ((1LL << i) <= level) {
            i++;
        }
        i--;
        node = P[i][node];
        level -= (1LL << i);
    }
    return node;
}

/*int dist(int p, int q) {
    return level[p] + level[q] - 2 * (level[LCA(p, q)]);
}*/

int distance(int a , int b)
{
    return abs(dist[a] - dist[b]);
}

void binarysearch(int node)
{
    int low = 1  ,ans = -1, high = level[node];
    while(low <= high){
        int mid = (low+high)/2;
        int par = parent(abs(mid-level[node]) , node);
        int dis = distance(node , par);
        if(par == node){
            break;
        }
        if(dis <= no[node]){
            high = mid-1;
            ans = par;
        }
        else{
            low = mid+1;
        }
    }
    if(ans != -1) {
        value[P[0][node]] += 1;
        if (ans != 1) {
            value[P[0][ans]] -= 1;
        }
    }
    return ;
}

void dfs1(int source) {
    visited[source] = true;
    for (int i = 0; i < v[source].size(); ++i) {
        if (visited[v[source][i].first] == false) {
            dfs1(v[source][i].first);
        }
    }
    fans[source] = value[source];
    value[P[0][source]] += value[source];
    return;
}

int32_t main() {
    scanf("%lld", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &no[i]);
    }
    for (int i = 2; i <= n; ++i) {
        int a, b;
        scanf("%lld", &a);
        scanf("%lld", &b);
        v[a].push_back({i, b});
    }
    dfs(1,1,1,0);
    precompute();
    for (int i = 2; i <= n; ++i) {
        binarysearch(i);
    }
    init();
    dfs1(1);
    for (int i = 1; i <= n; ++i) {
        printf("%lld ",fans[i]);
    }
    return 0;
}


#include<bits/stdc++.h>

#define int long long int
#define mp make_pair
using namespace std;

const int N = 1e6+10;
vector <pair <int, int> > v[N];
int no[N];
const int LG = log2(N) + 1;
int time1 = 0;
int P[LG][N];
int tin[N], tout[N], level[N];
int n;
int dist[N];
int value[N];
int fans[N];
bool visited[N];

void init()
{
    for (int i = 1; i <= n; ++i) {
        visited[i] = false;
    }
}

void dfs(int node, int par, int lvl,int d) {
    visited[node] = true;
    P[0][node] = par;
    level[node] = lvl;
    dist[node] = dist[par] + d;
    for (int i = 0 ; i<v[node].size();i++) {
        if(visited[v[node][i].first] == false) {
            dfs(v[node][i].first, node, lvl + 1, v[node][i].second);
        }
    }
}

void precompute() {
    for (int i = 1; i < LG; i++)
        for (int j = 1; j <= n; j++)
            if (P[i - 1][j])
                P[i][j] = P[i - 1][P[i - 1][j]];
}

int parent(int level, int node) {
    while (level) {
        int i = 0;
        while ((1LL << i) <= level) {
            i++;
        }
        i--;
        node = P[i][node];
        level -= (1LL << i);
    }
    return node;
}

/*int dist(int p, int q) {
    return level[p] + level[q] - 2 * (level[LCA(p, q)]);
}*/

int distance(int a , int b)
{
    return abs(dist[a] - dist[b]);
}

void binarysearch(int node)
{
    int low = 1  ,ans = -1, high = level[node];
    while(low <= high){
        int mid = (low+high)/2;
        int par = parent(abs(mid-level[node]) , node);
        int dis = distance(node , par);
        if(par == node){
            break;
        }
        if(dis <= no[node]){
            high = mid-1;
            ans = par;
        }
        else{
            low = mid+1;
        }
    }
    if(ans != -1) {
        value[P[0][node]] += 1;
        if (ans != 1) {
            value[P[0][ans]] -= 1;
        }
    }
    return ;
}

void dfs1(int source) {
    visited[source] = true;
    for (int i = 0; i < v[source].size(); ++i) {
        if (visited[v[source][i].first] == false) {
            dfs1(v[source][i].first);
        }
    }
    fans[source] = value[source];
    value[P[0][source]] += value[source];
    return;
}

int32_t main() {
    scanf("%lld", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%lld", &no[i]);
    }
    for (int i = 2; i <= n; ++i) {
        int a, b;
        scanf("%lld", &a);
        scanf("%lld", &b);
        v[a].push_back({i, b});
    }
    dfs(1,1,1,0);
    precompute();
    for (int i = 2; i <= n; ++i) {
        binarysearch(i);
    }
    init();
    dfs1(1);
    for (int i = 1; i <= n; ++i) {
        printf("%lld ",fans[i]);
    }
    return 0;
}


    // In the name of Allah
    // There is no power but from God the Almighty
    // No God except Allah
    #include <bits/stdc++.h>
    #define mp make_pair
    #define f1 first
    #define f2 second
    #define pb push_back
    #define pii pair<int ,int>
    #define ios  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define int long long
    using namespace std;
    const int mox=2e5+9;
    int na[mox];
    vector<pii> v[mox];
    int d[mox];
    int h[mox];
    vector<pii> g;
    int lc[mox][20];
    int f[mox];
    int w[mox];
    void dfs(int x)
    {
          for(pii i:v[x])
          {
                h[i.f1]=h[x]+1;
                d[i.f1]+=i.f2;
                lc[i.f1][0]=x;
                dfs(i.f1);
          }
    }
    int get(int x ,int a)
    {
        int p=h[x]-a;
       for(int i=19 ; i>=0 ; i--)
       {
          if(p>=(1<<i))
          {
             p-=(1<<i);
             x=lc[x][i];
          }
       }
       return x;
    }
    void dfs2(int x)
    {
      for(pii i:v[x])
      {
        dfs2(i.f1);
        f[x]+=f[i.f1];
      }
    }
    main()
    {
       ios
       int n;
       cin>>n;
       for(int i=1 ; i<=n ; i++)
       {
          cin>>na[i];
       }
       for(int i=2 ; i<=n ; i++)
       {
          int a,b;
          cin>>a>>b;
          v[a].pb({i,b});
       }
       dfs(1);
       for(int i=1 ; i<20 ; i++)
       {
           for(int j=1 ; j<=n ; j++)
           {
              lc[j][i]=lc[lc[j][i-1]][i-1];
           }
       }
       for(int i=1 ; i<=n ; i++)
       {
          g.pb({h[i],i});
       }
       sort(g.begin(),g.end());
       for(pii i:g)
       {
          d[i.f2]+=d[lc[i.f2][0]];
       }
       for(int i=1 ; i<=n  ; i++)
       {
          int low=-1;
          int hi=h[i];
          while(low<hi-1)
          {
             int mid=(low+hi)/2;
             if((d[i]-d[get(i,mid)])<=na[i])
             {
                hi=mid;
             }
             else
             low=mid;
          }
          f[i]+=1;
         if(low!=-1)
          f[get(i,low)]-=1;
          if(get(i,low)==i)
          {
             w[i]+=1;
          }
       }
       dfs2(1);
      for(int i=1 ; i<=n ; i++)
      {
        cout<<f[i]-1+w[i]<<" ";
      }
    }


    // In the name of Allah
    // There is no power but from God the Almighty
    // No God except Allah
    #include <bits/stdc++.h>
    #define mp make_pair
    #define f1 first
    #define f2 second
    #define pb push_back
    #define pii pair<int ,int>
    #define ios  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define int long long
    using namespace std;
    const int mox=2e5+9;
    int na[mox];
    vector<pii> v[mox];
    int d[mox];
    int h[mox];
    vector<pii> g;
    int lc[mox][20];
    int f[mox];
    int w[mox];
    void dfs(int x)
    {
          for(pii i:v[x])
          {
                h[i.f1]=h[x]+1;
                d[i.f1]+=i.f2;
                lc[i.f1][0]=x;
                dfs(i.f1);
          }
    }
    int get(int x ,int a)
    {
        int p=h[x]-a;
       for(int i=19 ; i>=0 ; i--)
       {
          if(p>=(1<<i))
          {
             p-=(1<<i);
             x=lc[x][i];
          }
       }
       return x;
    }
    void dfs2(int x)
    {
      for(pii i:v[x])
      {
        dfs2(i.f1);
        f[x]+=f[i.f1];
      }
    }
    main()
    {

       int n;
       cin>>n;
       for(int i=1 ; i<=n ; i++)
       {
          cin>>na[i];
       }
       for(int i=2 ; i<=n ; i++)
       {
          int a,b;
          cin>>a>>b;
          v[a].pb({i,b});
       }
       dfs(1);
       for(int i=1 ; i<20 ; i++)
       {
           for(int j=1 ; j<=n ; j++)
           {
              lc[j][i]=lc[lc[j][i-1]][i-1];
           }
       }
       for(int i=1 ; i<=n ; i++)
       {
          g.pb({h[i],i});
       }
       sort(g.begin(),g.end());
       for(pii i:g)
       {
          d[i.f2]+=d[lc[i.f2][0]];
       }
       for(int i=1 ; i<=n  ; i++)
       {
          int low=-1;
          int hi=h[i];
          while(low<hi-1)
          {
             int mid=(low+hi)/2;
             if((d[i]-d[get(i,mid)])<=na[i])
             {
                hi=mid;
             }
             else
             low=mid;
          }
          f[i]+=1;
         if(low!=-1)
          f[get(i,low)]-=1;
          if(get(i,low)==i)
          {
             w[i]+=1;
          }
       }
       dfs2(1);
      for(int i=1 ; i<=n ; i++)
      {
        cout<<f[i]-1+w[i]<<" ";
      }
    }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N= 2e5 + 5;
const ll mod=1e9 + 7;
#define debug(x) cerr<<#x<<" is "<<x<<endl;

const ll logN = 20;
ll n,u,v,w,p[N],sub[N],vis[N],dist[N],a[N],ans[N],dp[N][logN];
vector< pair<ll,ll> >adj[N];
void precompute(){
    memset(dp,-1,sizeof(dp));
    for(ll i=1;i<=n;i++)dp[i][0]=p[i];
    for(ll j=1;j<logN;j++)
        for(ll i=1;i<=n;i++)
            if(dp[i][j-1]!=-1)
                dp[i][j] = dp[dp[i][j-1]][j-1];
}
void dfs(ll node){
    vis[node]=1;
    for(ll i=0;i<adj[node].size();i++){
        v=adj[node][i].first;
        w=adj[node][i].second;
        if(!vis[v]){
            dist[v]=dist[node]+w;
            dfs(v);
        }
    }
}
ll solve(ll node){
    ll cur=node;
    for(ll j=logN-1;j>=0;j--)if(dp[cur][j]!=-1 && dist[node]-dist[dp[cur][j]]<=a[node])cur=dp[cur][j];
    if(cur!=-1)sub[p[cur]]++;
    ll res=0;
    for(ll i=0;i<adj[node].size();i++)res+=solve(adj[node][i].first);
    res-=sub[node];
    ans[node]=res;
    return res+1;
}
int main(){
    cin>>n;
    for(ll i=1;i<=n;i++)cin>>a[i];
    p[1]=-1;
    for(ll i=2;i<=n;i++){
        cin>>v>>w;
        adj[v].push_back(make_pair(i,w));
        p[i]=v;
    }
    dfs(1);
    precompute();
    solve(1);
    for(ll i=1;i<=n;i++)cout<<ans[i]<<" ";
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define boostIO                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define siz(v) (v.empty() ? 0 : v.size())
#define all(v) v.begin(), v.end()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define pb push_back
#define fi first
#define se second
#define int long long
#define mod 1000000007
#define rem 998244353
#define maxn 300005
const int INF = 1e18;
typedef pair<int, int> pii;

int n;
int a[maxn], w[maxn], p[maxn], ans[maxn];
vector<int> adj[maxn];
int dp1[maxn][20], dp2[maxn][20];

void dfs(int at, int fr) {
    dp1[at][0] = fr;
    dp2[at][0] = w[at];
    for (int i : adj[at]) {
        if (i == fr) continue;
        dfs(i, at);
    }
}

void dfs2(int at, int fr){
    for(int i : adj[at]){
        if(i == fr) continue;
        dfs2(i, at);
    }
    int u = at, val = a[u];
    rrep(i, 19, 0){
        if(dp2[u][i] <= val){
            val -= dp2[u][i];
            u = dp1[u][i];
        }
    }
    ans[fr]++;
    ans[p[u]]--;
}
void dfs3(int at, int fr){
    for(int i : adj[at]){
        if(i == fr) continue;
        dfs3(i, at);
        ans[at] += ans[i];
    }
}
signed main() {
    boostIO;
    cin >> n;
    repn(i, n) cin >> a[i];
    for (int i = 2, pr, wt; i <= n; i++) {
        cin >> p[i] >> w[i];
        adj[p[i]].pb(i), adj[i].pb(p[i]);
    }
    dfs(1, 0);

    repn(j, 19) repn(i, n) {
        dp1[i][j] = dp1[dp1[i][j - 1]][j - 1];
        dp2[i][j] = dp2[i][j - 1] + dp2[dp1[i][j - 1]][j - 1];
    }

    dfs2(1, 0);
    dfs3(1, 0);

    for(int i = 1; i <= n; i++){
        cout << ans[i] << " ";
    }
    return 0;
}
// XD


#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b;
int A[MAXN];
int par[MAXN][LOG];
int dist[MAXN][LOG];
int ans[MAXN];
vector<int> G[MAXN];

void dfs(int node){
	for (int i=1; i<LOG; i++) par[node][i]=par[par[node][i-1]][i-1];
	for (int i=1; i<LOG; i++) dist[node][i]=dist[par[node][i-1]][i-1] + dist[node][i-1];
	for (int v:G[node]){
		dfs(v);
		ans[node]+=ans[v];
	}
	ans[par[node][0]]++;
	int v=node, tmp=A[node];
	for (int i=LOG-1; i>=0; i--) if (dist[v][i]<=tmp){
		tmp-=dist[v][i];
		v=par[v][i];
	}
	v=par[v][0];
	//debug2(node, v)
	ans[v]--;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	for (int i=2; i<=n; i++){
		cin>>par[i][0]>>dist[i][0];
		G[par[i][0]].pb(i);
	}
	par[1][0]=0;
	dfs(1);
	for (int i=1; i<=n; i++) cout<<ans[i]<<' ';

	return 0;
}
/*
      ___           ___                            ___           ___           ___           ___           ___           ___
     /\  \         /\__\      ___                 /\  \         /\__\         /\  \         /\__\         /\  \         /\__\      ___
    /::\  \       /:/  /     /\  \               /::\  \       /:/  /        /::\  \       /:/  /        /::\  \       /:/  /     /\  \
   /:/\:\  \     /:/  /      \:\  \             /:/\ \  \     /:/__/        /:/\:\  \     /:/__/        /:/\:\  \     /:/  /      \:\  \
  /::\~\:\  \   /:/  /       /::\__\           _\:\~\ \  \   /::\  \ ___   /::\~\:\  \   /::\  \ ___   /::\~\:\  \   /:/  /       /::\__\
 /:/\:\ \:\__\ /:/__/     __/:/\/__/          /\ \:\ \ \__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/__/     __/:/\/__/
 \/__\:\/:/  / \:\  \    /\/:/  /             \:\ \:\ \/__/ \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \:\  \    /\/:/  /
      \::/  /   \:\  \   \::/__/               \:\ \:\__\        \::/  /       \::/  /       \::/  /       \::/  /   \:\  \   \::/__/
      /:/  /     \:\  \   \:\__\                \:\/:/  /        /:/  /        /:/  /        /:/  /        /:/  /     \:\  \   \:\__\
     /:/  /       \:\__\   \/__/                 \::/  /        /:/  /        /:/  /        /:/  /        /:/  /       \:\__\   \/__/
     \/__/         \/__/                          \/__/         \/__/         \/__/         \/__/         \/__/         \/__/
*/


#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG=20;

int n, m, k, u, v, x, y, t, a, b;
ll A[MAXN];
int par[MAXN][LOG];
ll dist[MAXN][LOG];
int ans[MAXN];
vector<int> G[MAXN];

void dfs(int node){
	for (int i=1; i<LOG; i++) par[node][i]=par[par[node][i-1]][i-1];
	for (int i=1; i<LOG; i++) dist[node][i]=min(1ll*inf, dist[par[node][i-1]][i-1] + dist[node][i-1]);
	for (int v:G[node]){
		dfs(v);
		ans[node]+=ans[v];
	}
	ans[par[node][0]]++;
	ll v=node, tmp=A[node];
	for (int i=LOG-1; i>=0; i--) if (dist[v][i]<=tmp){
		tmp-=dist[v][i];
		v=par[v][i];
	}
	v=par[v][0];
	//debug2(node, v)
	ans[v]--;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	for (int i=2; i<=n; i++){
		cin>>par[i][0]>>dist[i][0];
		G[par[i][0]].pb(i);
	}
	par[1][0]=0;
	dfs(1);
	for (int i=1; i<=n; i++) cout<<ans[i]<<' ';

	return 0;
}
/*
      ___           ___                            ___           ___           ___           ___           ___           ___
     /\  \         /\__\      ___                 /\  \         /\__\         /\  \         /\__\         /\  \         /\__\      ___
    /::\  \       /:/  /     /\  \               /::\  \       /:/  /        /::\  \       /:/  /        /::\  \       /:/  /     /\  \
   /:/\:\  \     /:/  /      \:\  \             /:/\ \  \     /:/__/        /:/\:\  \     /:/__/        /:/\:\  \     /:/  /      \:\  \
  /::\~\:\  \   /:/  /       /::\__\           _\:\~\ \  \   /::\  \ ___   /::\~\:\  \   /::\  \ ___   /::\~\:\  \   /:/  /       /::\__\
 /:/\:\ \:\__\ /:/__/     __/:/\/__/          /\ \:\ \ \__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/__/     __/:/\/__/
 \/__\:\/:/  / \:\  \    /\/:/  /             \:\ \:\ \/__/ \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \:\  \    /\/:/  /
      \::/  /   \:\  \   \::/__/               \:\ \:\__\        \::/  /       \::/  /       \::/  /       \::/  /   \:\  \   \::/__/
      /:/  /     \:\  \   \:\__\                \:\/:/  /        /:/  /        /:/  /        /:/  /        /:/  /     \:\  \   \:\__\
     /:/  /       \:\__\   \/__/                 \::/  /        /:/  /        /:/  /        /:/  /        /:/  /       \:\__\   \/__/
     \/__/         \/__/                          \/__/         \/__/         \/__/         \/__/         \/__/         \/__/
*/


#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG=20;

int n, m, k, u, v, x, y, t, a, b;
ll A[MAXN];
int par[MAXN][LOG];
ll dist[MAXN][LOG];
int ans[MAXN];
vector<int> G[MAXN];

void dfs(int node){
	for (int i=1; i<LOG; i++) par[node][i]=par[par[node][i-1]][i-1];
	for (int i=1; i<LOG; i++) dist[node][i]=min(inf, dist[par[node][i-1]][i-1] + dist[node][i-1]);
	for (int v:G[node]){
		dfs(v);
		ans[node]+=ans[v];
	}
	ans[par[node][0]]++;
	ll v=node, tmp=A[node];
	for (int i=LOG-1; i>=0; i--) if (dist[v][i]<=tmp){
		tmp-=dist[v][i];
		v=par[v][i];
	}
	v=par[v][0];
	//debug2(node, v)
	ans[v]--;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	for (int i=2; i<=n; i++){
		cin>>par[i][0]>>dist[i][0];
		G[par[i][0]].pb(i);
	}
	par[1][0]=0;
	dfs(1);
	for (int i=1; i<=n; i++) cout<<ans[i]<<' ';

	return 0;
}
/*
      ___           ___                            ___           ___           ___           ___           ___           ___
     /\  \         /\__\      ___                 /\  \         /\__\         /\  \         /\__\         /\  \         /\__\      ___
    /::\  \       /:/  /     /\  \               /::\  \       /:/  /        /::\  \       /:/  /        /::\  \       /:/  /     /\  \
   /:/\:\  \     /:/  /      \:\  \             /:/\ \  \     /:/__/        /:/\:\  \     /:/__/        /:/\:\  \     /:/  /      \:\  \
  /::\~\:\  \   /:/  /       /::\__\           _\:\~\ \  \   /::\  \ ___   /::\~\:\  \   /::\  \ ___   /::\~\:\  \   /:/  /       /::\__\
 /:/\:\ \:\__\ /:/__/     __/:/\/__/          /\ \:\ \ \__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/__/     __/:/\/__/
 \/__\:\/:/  / \:\  \    /\/:/  /             \:\ \:\ \/__/ \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \:\  \    /\/:/  /
      \::/  /   \:\  \   \::/__/               \:\ \:\__\        \::/  /       \::/  /       \::/  /       \::/  /   \:\  \   \::/__/
      /:/  /     \:\  \   \:\__\                \:\/:/  /        /:/  /        /:/  /        /:/  /        /:/  /     \:\  \   \:\__\
     /:/  /       \:\__\   \/__/                 \::/  /        /:/  /        /:/  /        /:/  /        /:/  /       \:\__\   \/__/
     \/__/         \/__/                          \/__/         \/__/         \/__/         \/__/         \/__/         \/__/
*/


#include <bits/stdc++.h>
#if defined(__GNUC__)
#pragma GCC optimize ("Ofast")
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010, LOG=20;

int n, m, k, u, v, x, y, t, a, b;
int A[MAXN];
int par[MAXN][LOG];
int dist[MAXN][LOG];
int ans[MAXN];
vector<int> G[MAXN];

void dfs(int node){
	for (int i=1; i<LOG; i++) par[node][i]=par[par[node][i-1]][i-1];
	for (int i=1; i<LOG; i++) dist[node][i]=dist[par[node][i-1]][i-1] + dist[node][i-1];
	for (int v:G[node]){
		dfs(v);
		ans[node]+=ans[v];
	}
	ans[par[node][0]]++;
	int v=node, tmp=A[node];
	for (int i=LOG-1; i>=0; i--) if (dist[v][i]<=tmp){
		tmp-=dist[v][i];
		v=par[v][i];
	}
	v=par[v][0];
	//debug2(node, v)
	ans[v]--;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n;
	for (int i=1; i<=n; i++) cin>>A[i];
	for (int i=2; i<=n; i++){
		cin>>par[i][0]>>dist[i][0];
		G[par[i][0]].pb(i);
	}
	par[1][0]=0;
	dfs(1);
	for (int i=1; i<=n; i++) cout<<ans[i]<<' ';

	return 0;
}
/*
      ___           ___                            ___           ___           ___           ___           ___           ___
     /\  \         /\__\      ___                 /\  \         /\__\         /\  \         /\__\         /\  \         /\__\      ___
    /::\  \       /:/  /     /\  \               /::\  \       /:/  /        /::\  \       /:/  /        /::\  \       /:/  /     /\  \
   /:/\:\  \     /:/  /      \:\  \             /:/\ \  \     /:/__/        /:/\:\  \     /:/__/        /:/\:\  \     /:/  /      \:\  \
  /::\~\:\  \   /:/  /       /::\__\           _\:\~\ \  \   /::\  \ ___   /::\~\:\  \   /::\  \ ___   /::\~\:\  \   /:/  /       /::\__\
 /:/\:\ \:\__\ /:/__/     __/:/\/__/          /\ \:\ \ \__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/\:\  /\__\ /:/\:\ \:\__\ /:/__/     __/:/\/__/
 \/__\:\/:/  / \:\  \    /\/:/  /             \:\ \:\ \/__/ \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \/__\:\/:/  / \:\  \    /\/:/  /
      \::/  /   \:\  \   \::/__/               \:\ \:\__\        \::/  /       \::/  /       \::/  /       \::/  /   \:\  \   \::/__/
      /:/  /     \:\  \   \:\__\                \:\/:/  /        /:/  /        /:/  /        /:/  /        /:/  /     \:\  \   \:\__\
     /:/  /       \:\__\   \/__/                 \::/  /        /:/  /        /:/  /        /:/  /        /:/  /       \:\__\   \/__/
     \/__/         \/__/                          \/__/         \/__/         \/__/         \/__/         \/__/         \/__/
*/


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define long long long
void _read();

const int nax = 2e5+11;
int n;
vector<vector<pair<int,int>>> adj;
oset<pair<long,int>> s;
vector<int> a,ans;
vector<long> dp,vec;
int in = 0;
void dfs_1( int u = 1, int p = 1, int W = 0) {
      dp[u] = W;
      vec[u] = dp[u] - a[u];
      for( const auto &[v,w] : adj[u]) {
            if( v == p ) continue;
            dfs_1(v,u,w+W);
      }
}
void dfs( int u = 1, int p = 1) {
      for( const auto &[v,w] : adj[u]) {
            if ( v == p ) continue;
            long bef = s.order_of_key({dp[u],0});
            dfs(v,u);
            long af = s.order_of_key({dp[u],0});
            ans[v] = af-bef;
            s.insert({vec[u],--in});
      }
}

int32_t main () { _read();

      cin >> n;
      a.resize(n+1);
      dp.resize(n+1);
      adj.resize(n+1);
      vec.resize(n+1);
      ans.resize(n+1);
      for( int i = 1; i <= n; i++) {
            cin >> a[i];
      }
      for( int i = 2; i <= n; i++) {
            int p,w;
            cin >> p >> w;
            adj[i].emplace_back(p,w);
            adj[p].emplace_back(i,w);
      }
      dfs_1();
      dfs();
      ans[1] = s.order_of_key({dp[1],0});
      for( int i = 1; i <= n; i++) {
            cout << ans[i] << ' ';
      }
      cout << '\n';
      return 0;
};

void _read() {
      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define int long long
void _read();

const int nax = 2e5+11;
int n;
vector<vector<pair<int,int>>> adj;
oset<pair<int,int>> s;
vector<int> a,ans;
vector<int> dp,vec;
int in = 0;
void dfs_1( int u = 1, int p = 1, int W = 0) {
      dp[u] = W;
      vec[u] = dp[u] - a[u];
      for( const auto &[v,w] : adj[u]) {
            if( v == p ) continue;
            dfs_1(v,u,w+W);
      }
}
void dfs( int u = 1, int p = 1) {
      for( const auto &[v,w] : adj[u]) {
            if ( v == p ) continue;
            int bef = s.order_of_key({dp[v],0});
            dfs(v,u);
            int af = s.order_of_key({dp[v],0});
            ans[v] = af-bef;
            s.insert({vec[v],--in});
      }
}

int32_t main () { _read();

      cin >> n;
      a.resize(n+1);
      dp.resize(n+1);
      adj.resize(n+1);
      vec.resize(n+1);
      ans.resize(n+1);
      for( int i = 1; i <= n; i++) {
            cin >> a[i];
      }
      for( int i = 2; i <= n; i++) {
            int p,w;
            cin >> p >> w;
            adj[i].emplace_back(p,w);
            adj[p].emplace_back(i,w);
      }
      dfs_1();
      dfs();
      ans[1] = (int) s.order_of_key({dp[1],0});
      for( int i = 1; i <= n; i++) {
            cout << ans[i] << ' ';
      }
      cout << '\n';
      return 0;
};

void _read() {
      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define A(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define long long long
void _read();

const int nax = 2e5+11;
int n;
vector<vector<pair<int,int>>> adj;
oset<pair<long,int>> s;
vector<int> a,ans;
vector<long> dp,vec;
int in = 0;
void dfs_1( int u = 1, int p = 1, int W = 0) {
      dp[u] = W;
      vec[u] = dp[u] - a[u];
      for( const auto &[v,w] : adj[u]) {
            if( v == p ) continue;
            dfs_1(v,u,w+W);
      }
}
void dfs( int u = 1, int p = 1) {
      for( const auto &[v,w] : adj[u]) {
            if ( v == p ) continue;
            int bef = s.order_of_key({dp[v],0});
            dfs(v,u);
            int af = s.order_of_key({dp[v],0});
            ans[v] = af-bef;
            s.insert({vec[v],--in});
      }
}

int32_t main () { _read();

      cin >> n;
      a.resize(n+1);
      dp.resize(n+1);
      adj.resize(n+1);
      vec.resize(n+1);
      ans.resize(n+1);
      for( int i = 1; i <= n; i++) {
            cin >> a[i];
      }
      for( int i = 2; i <= n; i++) {
            int p,w;
            cin >> p >> w;
            adj[i].emplace_back(p,w);
            adj[p].emplace_back(i,w);
      }
      dfs_1();
      dfs();
      ans[1] = (int) s.order_of_key({dp[1],0});
      for( int i = 1; i <= n; i++) {
            cout << ans[i] << ' ';
      }
      cout << '\n';
      return 0;
};

void _read() {
      ios_base :: sync_with_stdio(false);
      cin.tie(NULL);
      #ifdef LOCAL
      freopen("input.txt","r",stdin);
      #endif
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using ll = long long;

template <class K, class V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<K, V, std::less_equal<K>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

int t = 0;
const int maxn = 2e5+5;
int n, a[maxn];
struct Edge
{
    int to, wt;
};

void merge(ordered_set<ll>& a, ordered_set<ll>& b) {
    if (a.size() < b.size()) swap(a,b);
    for (ll i: b) {
        a.insert(i);
    }
}

vector<Edge> adj[maxn];
ordered_set<ll> os;
int ans[maxn];
ordered_set<ll>* dfs(int i, ll d) {
    if (adj[i].size() == 0) {
        ordered_set<ll>* ret = new ordered_set<ll>;
        ret->insert(d);
        return ret;
    }
    else {
        ordered_set<ll>* ret = new ordered_set<ll>;
        for (Edge e: adj[i]) {
            auto nj = dfs(e.to,d+e.wt);
            merge(*ret,*nj);
        }
        /*
        cout << i << ":\n";
        for (int j: (*ret)) {
            cout << j << ' ';
        }
        cout << '\n';
        */
        ans[i] = ret->order_of_key(d+a[i]+1);
        ret->insert(d);
        return ret;
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n-1; i++) {
        int pi, wi; cin >> pi >> wi;
        adj[pi].push_back({i+1,wi});
    }
    dfs(1,0);
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int maxn = 2e5+5;
int n, a[maxn];
struct Edge
{
    int to, wt;
};

vector<Edge> adj[maxn];
int par[20][maxn];
ll depth[maxn];

void dfs(int i, ll d) {
    depth[i] = d;
    for (Edge e: adj[i]) {
        dfs(e.to,d+e.wt);
    }
}

int ans[maxn];

void dfs2(int i) {
    for (Edge e: adj[i]) {
        dfs2(e.to);
        ans[i] += ans[e.to];
    }
    //cout << i << ": " << ans[i] << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n-1; i++) {
        int pi, wi; cin >> pi >> wi;
        adj[pi].push_back({i+1,wi});
        par[0][i+1] = pi;
    }
    for (int k = 1; k < 20; k++) {
        for (int i = 1; i <= n; i++) {
            par[k][i] = par[k-1][par[k-1][i]];
        }
    }
    dfs(1,0);
    for (int i = 1; i <= n; i++) {
        ll target = depth[i] - a[i];
        int j = i;
        for (int k = 19; k >= 0; k--) {
            int nj = par[k][j];
            if (nj == 0) continue;
            if (depth[nj] >= target) {
                j = nj;
            }
        }
        j = par[0][j];
        /*
        cout << target << '\n';
        cout << i << ": " << j << '\n';
        */
        ans[par[0][i]]++;
        ans[j]--;
    }
    dfs2(1);
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using ll = long long;

template <class K, class V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<K, V, std::less_equal<K>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

int t = 0;
const int maxn = 2e5+5;
int n, a[maxn];
struct Edge
{
    int to, wt;
};

void merge(ordered_set<ll>& a, ordered_set<ll>& b) {
    if (a.size() < b.size()) swap(a,b);
    for (ll i: b) {
        a.insert(i);
    }
}

vector<Edge> adj[maxn];
ordered_set<ll> os;
int ans[maxn];
ordered_set<ll>* dfs(int i, ll d) {
    if (adj[i].size() == 0) {
        ordered_set<ll>* ret = new ordered_set<ll>;
        ret->insert(d-a[i]);
        return ret;
    }
    else {
        ordered_set<ll>* ret = new ordered_set<ll>;
        for (Edge e: adj[i]) {
            auto nj = dfs(e.to,d+e.wt);
            merge(*ret,*nj);
        }
        /*
        cout << i << ":\n";
        for (int j: (*ret)) {
            cout << j << ' ';
        }
        cout << '\n';
        */
        ans[i] = ret->order_of_key(d+1);
        ret->insert(d-a[i]);
        return ret;
    }
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= n-1; i++) {
        int pi, wi; cin >> pi >> wi;
        adj[pi].push_back({i+1,wi});
    }
    dfs(1,0);
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;

#define mp make_pair
#define pb push_back
#define f first
#define s second

mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

vii cur;
void dfs(int u, int p, vector<vi> &g, vi &a, vi &add, vi &pref, vi &rem) {
    cur.push_back({(cur.empty() ? 0 : cur.back().f + add[u]), u});
    int find = cur.back().f - a[u];
    auto it = lower_bound(cur.begin(), cur.end(), mp(find, -1));
    if (it->s != u) {
        pref[next(it)->s]++;
        rem[u]++;
    }
    for (auto &v : g[u]) {
        dfs(v, u, g, a, add, pref, rem);
    }
    cur.pop_back();
}

int s = 0;
void dfs2(int u, vi &ans, vector<vi> &g, vi &pref, vi &rem) {
    s -= rem[u];
    ans[u] = s;
    for (auto &v : g[u]) {
        s += pref[v];
        ans[u] += pref[v];
        dfs2(v, ans, g, pref, rem);
        s -= pref[v];
    }
    s += rem[u];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi a(n);
    for (auto &x : a) cin >> x;
    vector<vi> g(n);
    vi add(n), pref(n), rem(n);
    for (int i = 1, p, v; i < n; i++) {
        cin >> p >> v, p--;
        g[p].push_back(i);
        add[i] = v;
    }

    dfs(0, -1, g, a, add, pref, rem);

    vi ans(n);
    dfs2(0, ans, g, pref, rem);
    assert(s == 0);
    for (auto &x : ans) cout << x << " ";
    cout << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;

#define mp make_pair
#define pb push_back
#define f first
#define s second

mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

vector<pair<ll, int>> cur;
void dfs(int u, int p, vector<vi> &g, vl &a, vl &add, vi &pref) {
    cur.push_back({(cur.empty() ? add[u] : cur.back().f + add[u]), u});
    ll find = cur.back().f - a[u];
    auto it = lower_bound(cur.begin(), cur.end(), mp(find, -1));
    pref[u]++;
    pref[it->s]--;
    for (auto &v : g[u]) {
        dfs(v, u, g, a, add, pref);
    }
    cur.pop_back();
}

int s = 0;
void dfs2(int u, vi &ans, vector<vi> &g, vi &pref) {
    for (auto &v : g[u]) {
        dfs2(v, ans, g, pref);
        ans[u] += ans[v] + pref[v];
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vl a(n);
    for (auto &x : a) cin >> x;
    vector<vi> g(n);
    vl add(n); vi pref(n), rem(n);
    for (int i = 1, p, v; i < n; i++) {
        cin >> p >> v, p--;
        g[p].push_back(i);
        add[i] = v;
    }

    dfs(0, -1, g, a, add, pref);

    vi ans(n);
    dfs2(0, ans, g, pref);
    for (auto &x : ans) cout << x << " ";
    cout << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;

#define mp make_pair
#define pb push_back
#define f first
#define s second

mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

vector<pair<ll, int>> cur;
void dfs(int u, int p, vector<vi> &g, vl &a, vl &add, vi &pref, vi &rem) {
    cur.push_back({(cur.empty() ? add[u] : cur.back().f + add[u]), u});
    ll find = cur.back().f - a[u];
    auto it = lower_bound(cur.begin(), cur.end(), mp(find, -1));
    if (it->s != u) {
        pref[next(it)->s]++;
        rem[u]++;
    }
    for (auto &v : g[u]) {
        dfs(v, u, g, a, add, pref, rem);
    }
    cur.pop_back();
}

int s = 0;
void dfs2(int u, vi &ans, vector<vi> &g, vi &pref, vi &rem) {
    s -= rem[u];
    ans[u] = s;
    for (auto &v : g[u]) {
        s += pref[v];
        ans[u] += pref[v];
        dfs2(v, ans, g, pref, rem);
        s -= pref[v];
    }
    s += rem[u];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vl a(n);
    for (auto &x : a) cin >> x;
    vector<vi> g(n);
    vl add(n); vi pref(n), rem(n);
    for (int i = 1, p, v; i < n; i++) {
        cin >> p >> v, p--;
        g[p].push_back(i);
        add[i] = v;
    }

    dfs(0, -1, g, a, add, pref, rem);

    vi ans(n);
    dfs2(0, ans, g, pref, rem);
    for (auto &x : ans) cout << x << " ";
    cout << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;

#define mp make_pair
#define pb push_back
#define f first
#define s second

mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

vii cur;
void dfs(int u, int p, vector<vi> &g, vi &a, vi &add, vi &pref, vi &rem) {
    cur.push_back({(cur.empty() ? 0 : cur.back().f + add[u]), u});
    int find = cur.back().f - a[u];
    auto it = lower_bound(cur.begin(), cur.end(), mp(find, -1));
    if (it->s != u) {
        pref[next(it)->s]++;
        rem[u]++;
    }
    for (auto &v : g[u]) {
        dfs(v, u, g, a, add, pref, rem);
    }
    cur.pop_back();
}

int s = 0;
void dfs2(int u, vi &ans, vector<vi> &g, vi &pref, vi &rem) {
    s -= rem[u];
    ans[u] = s;
    for (auto &v : g[u]) {
        s += pref[v];
        ans[u] += pref[v];
        dfs2(v, ans, g, pref, rem);
        s -= pref[v];
    }
    s += rem[u];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi a(n);
    for (auto &x : a) cin >> x;
    vector<vi> g(n);
    vi add(n), pref(n), rem(n);
    for (int i = 1, p, v; i < n; i++) {
        cin >> p >> v, p--;
        g[p].push_back(i);
        add[i] = v;
    }

    dfs(0, -1, g, a, add, pref, rem);

    vi ans(n);
    dfs2(0, ans, g, pref, rem);
    for (auto &x : ans) cout << x << " ";
    cout << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;

#define mp make_pair
#define pb push_back
#define f first
#define s second

mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

vector<pair<ll, int>> cur;
void dfs(int u, int p, vector<vi> &g, vl &a, vl &add, vi &pref) {
    cur.push_back({(cur.empty() ? add[u] : cur.back().f + add[u]), u});
    ll find = cur.back().f - a[u];
    auto it = lower_bound(cur.begin(), cur.end(), mp(find, -1));
    pref[u]++;
    pref[it->s]--;
    for (auto &v : g[u]) {
        dfs(v, u, g, a, add, pref);
    }
    cur.pop_back();
}

int s = 0;
void dfs2(int u, vi &ans, vector<vi> &g, vi &pref) {
    for (auto &v : g[u]) {
        dfs2(v, ans, g, pref);
    }
    ans[u] = s;
    s += pref[u];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vl a(n);
    for (auto &x : a) cin >> x;
    vector<vi> g(n);
    vl add(n); vi pref(n), rem(n);
    for (int i = 1, p, v; i < n; i++) {
        cin >> p >> v, p--;
        g[p].push_back(i);
        add[i] = v;
    }

    dfs(0, -1, g, a, add, pref);

    vi ans(n);
    dfs2(0, ans, g, pref);
    for (auto &x : ans) cout << x << " ";
    cout << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;

#define mp make_pair
#define pb push_back
#define f first
#define s second

mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

vector<pair<ll, int>> cur;
void dfs(int u, int p, vector<vi> &g, vi &a, vl &add, vi &pref, vi &rem) {
    cur.push_back({(cur.empty() ? 0 : cur.back().f + add[u]), u});
    int find = cur.back().f - a[u];
    auto it = lower_bound(cur.begin(), cur.end(), mp(find, -1));
    if (it->s != u) {
        pref[next(it)->s]++;
        rem[u]++;
    }
    for (auto &v : g[u]) {
        dfs(v, u, g, a, add, pref, rem);
    }
    cur.pop_back();
}

int s = 0;
void dfs2(int u, vi &ans, vector<vi> &g, vi &pref, vi &rem) {
    s -= rem[u];
    ans[u] = s;
    for (auto &v : g[u]) {
        s += pref[v];
        ans[u] += pref[v];
        dfs2(v, ans, g, pref, rem);
        s -= pref[v];
    }
    s += rem[u];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi a(n);
    for (auto &x : a) cin >> x;
    vector<vi> g(n);
    vl add(n); vi pref(n), rem(n);
    for (int i = 1, p, v; i < n; i++) {
        cin >> p >> v, p--;
        g[p].push_back(i);
        add[i] = v;
    }

    dfs(0, -1, g, a, add, pref, rem);

    vi ans(n);
    dfs2(0, ans, g, pref, rem);
    for (auto &x : ans) cout << x << " ";
    cout << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;

#define mp make_pair
#define pb push_back
#define f first
#define s second

mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

vector<pair<ll, int>> cur;
void dfs(int u, int p, vector<vi> &g, vi &a, vl &add, vi &pref, vi &rem) {
    cur.push_back({(cur.empty() ? 0 : cur.back().f + add[u]), u});
    ll find = cur.back().f - a[u];
    auto it = lower_bound(cur.begin(), cur.end(), mp(find, -1));
    if (it->s != u) {
        pref[next(it)->s]++;
        rem[u]++;
    }
    for (auto &v : g[u]) {
        dfs(v, u, g, a, add, pref, rem);
    }
    cur.pop_back();
}

int s = 0;
void dfs2(int u, vi &ans, vector<vi> &g, vi &pref, vi &rem) {
    s -= rem[u];
    ans[u] = s;
    for (auto &v : g[u]) {
        s += pref[v];
        ans[u] += pref[v];
        dfs2(v, ans, g, pref, rem);
        s -= pref[v];
    }
    s += rem[u];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    vi a(n);
    for (auto &x : a) cin >> x;
    vector<vi> g(n);
    vl add(n); vi pref(n), rem(n);
    for (int i = 1, p, v; i < n; i++) {
        cin >> p >> v, p--;
        g[p].push_back(i);
        add[i] = v;
    }

    dfs(0, -1, g, a, add, pref, rem);

    vi ans(n);
    dfs2(0, ans, g, pref, rem);
    for (auto &x : ans) cout << x << " ";
    cout << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/


#include <bits/stdc++.h>

#define INF (ll)1e18
#define EPS 1e-8
#define pb push_back
#define pause system("pause")
#define exit exit(0)

using namespace std;
using ull = unsigned long long;
using ll = long long;

typedef pair<int, int> pii;

int n, m;
ll a[100005];
ll s[100005];
ll v[100005], vv[200005];
int fst[100005], lst[100005];
vector<pii> g[100005];
vector<int> ord;
vector<ll> t[800005];

void build(int v, int vl, int vr) {
	if (vl == vr) {
		t[v] = { vv[vl] };
		return;
	}

	int m = (vl + vr) / 2;
	build(2 * v, vl, m);
	build(2 * v + 1, m + 1, vr);

	merge(t[2 * v].begin(), t[2 * v].end(), t[2 * v + 1].begin(), t[2 * v + 1].end(), back_inserter(t[v]));
}

int get(int v, int vl, int vr, int l, int r, int x) {
	if (r < vl || vr < l || r < l) {
		return 0;
	}

	if (l <= vl && vr <= r) {
		return upper_bound(t[v].begin(), t[v].end(), x) - t[v].begin();
	}

	int m = (vl + vr) >> 1;
	return get(2 * v, vl, m, l, r, x) + get(2 * v + 1, m + 1, vr, l, r, x);
}

void dfs(int u) {
	ord.pb(u);
	fst[u] = (int)ord.size() - 1;
	for (auto v : g[u]) {
		s[v.first] = s[u] + v.second;
		dfs(v.first);
	}

	ord.pb(u);
	lst[u] = (int)ord.size() - 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}

	for (int i = 2, p, w; i <= n; ++i) {
		cin >> p >> w;
		g[p].pb({ i, w });
	}

	dfs(1);
	for (int i = 1; i <= n; ++i) {
		v[i] = s[i] - a[i];
	}

	int sz = (int)ord.size();
	for (int i = 0; i < sz; ++i) {
		vv[i] = v[ord[i]];
	}

	build(1, 0, sz - 1);

	for (int i = 1; i <= n; ++i) {
		cout << get(1, 0, sz - 1, fst[i] + 1, lst[i] - 1, s[i]) / 2 << ' ';
	}
	cout << endl;
	//pause;
	return 0;
}


#include <bits/stdc++.h>

#define INF (ll)1e18
#define EPS 1e-8
#define pb push_back
#define pause system("pause")
#define exit exit(0)

using namespace std;
using ull = unsigned long long;
using ll = long long;

typedef pair<int, int> pii;

int n;
ll a[200005], s[200005];
int val[200005], ans[200005], par[200005];
vector<pii> g[200005];
vector<int> ord;

void dfs(int u) {
	for (auto v : g[u]) {
		s[v.first] = s[u] + v.second;
		dfs(v.first);
	}
}

void dfs2(int u) {
	int l = -1, r = (int)ord.size(), m;
 	while (r - l > 1) {
		m = (l + r) >> 1;
		if (s[ord[m]] < s[u] - a[u]) {
			l = m;
		} else {
			r = m;
		}
	}

	if (r != (int)ord.size()) {
		--val[par[ord[r]]];
		++val[ord.back()];
	}

	for (auto v : g[u]) {
		ord.pb(u);
		dfs2(v.first);
		ord.pop_back();
	}
}

void dfs3(int u) {
	for (auto v : g[u]) {
		dfs3(v.first);
		val[u] += val[v.first];
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}

	for (int i = 2, p, w; i <= n; ++i) {
		cin >> p >> w;
		g[p].pb({ i, w });
		par[i] = p;
	}

	dfs(1);
	dfs2(1);
	dfs3(1);

	for (int i = 1; i <= n; ++i) {
		cout << val[i] << ' ';
	}
	cout << endl;
	//pause;
	return 0;
}


#include <bits/stdc++.h>

#define INF (ll)1e18
#define EPS 1e-8
#define pb push_back
#define pause system("pause")
#define exit exit(0)

using namespace std;
using ull = unsigned long long;
using ll = long long;

typedef pair<int, int> pii;

int n, m;
ll a[200005];
ll s[200005];
ll v[200005], vv[400005];
int fst[200005], lst[200005];
vector<pii> g[200005];
vector<int> ord;
vector<ll> t[1600005];

void build(int v, int vl, int vr) {
	if (vl == vr) {
		t[v] = { vv[vl] };
		return;
	}

	int m = (vl + vr) / 2;
	build(2 * v, vl, m);
	build(2 * v + 1, m + 1, vr);

	merge(t[2 * v].begin(), t[2 * v].end(), t[2 * v + 1].begin(), t[2 * v + 1].end(), back_inserter(t[v]));
}

int get(int v, int vl, int vr, int l, int r, int x) {
	if (r < vl || vr < l || r < l) {
		return 0;
	}

	if (l <= vl && vr <= r) {
		return upper_bound(t[v].begin(), t[v].end(), x) - t[v].begin();
	}

	int m = (vl + vr) >> 1;
	return get(2 * v, vl, m, l, r, x) + get(2 * v + 1, m + 1, vr, l, r, x);
}

void dfs(int u) {
	ord.pb(u);
	fst[u] = (int)ord.size() - 1;
	for (auto v : g[u]) {
		s[v.first] = s[u] + v.second;
		dfs(v.first);
	}

	ord.pb(u);
	lst[u] = (int)ord.size() - 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}

	for (int i = 2, p, w; i <= n; ++i) {
		cin >> p >> w;
		g[p].pb({ i, w });
	}

	dfs(1);
	for (int i = 1; i <= n; ++i) {
		v[i] = s[i] - a[i];
	}

	int sz = (int)ord.size();
	for (int i = 0; i < sz; ++i) {
		vv[i] = v[ord[i]];
	}

	build(1, 0, sz - 1);

	for (int i = 1; i <= n; ++i) {
		cout << get(1, 0, sz - 1, fst[i] + 1, lst[i] - 1, s[i]) / 2 << ' ';
	}
	cout << endl;
	//pause;
	return 0;
}


#include <bits/stdc++.h>

#define INF (ll)1e18
#define EPS 1e-8
#define pb push_back
#define pause system("pause")
#define exit exit(0)

using namespace std;
using ull = unsigned long long;
using ll = long long;

typedef pair<int, int> pii;

int n, m;
int a[100005];
ll s[100005];
ll v[100005], vv[200005];
int fst[100005], lst[100005];
vector<pii> g[100005];
vector<int> ord;
vector<ll> t[800005];

void build(int v, int vl, int vr) {
	if (vl == vr) {
		t[v] = { vv[vl] };
		return;
	}

	int m = (vl + vr) / 2;
	build(2 * v, vl, m);
	build(2 * v + 1, m + 1, vr);

	merge(t[2 * v].begin(), t[2 * v].end(), t[2 * v + 1].begin(), t[2 * v + 1].end(), back_inserter(t[v]));
}

int get(int v, int vl, int vr, int l, int r, int x) {
	if (r < vl || vr < l || r < l) {
		return 0;
	}

	if (l <= vl && vr <= r) {
		return upper_bound(t[v].begin(), t[v].end(), x) - t[v].begin();
	}

	int m = (vl + vr) >> 1;
	return get(2 * v, vl, m, l, r, x) + get(2 * v + 1, m + 1, vr, l, r, x);
}

void dfs(int u) {
	ord.pb(u);
	fst[u] = (int)ord.size() - 1;
	for (auto v : g[u]) {
		s[v.first] = s[u] + v.second;
		dfs(v.first);
	}

	ord.pb(u);
	lst[u] = (int)ord.size() - 1;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}

	for (int i = 2, p, w; i <= n; ++i) {
		cin >> p >> w;
		g[p].pb({ i, w });
	}

	dfs(1);
	for (int i = 1; i <= n; ++i) {
		v[i] = s[i] - a[i];
	}

	int sz = (int)ord.size();
	for (int i = 0; i < sz; ++i) {
		vv[i] = v[ord[i]];
	}

	build(1, 0, sz - 1);

	for (int i = 1; i <= n; ++i) {
		cout << get(1, 0, sz - 1, fst[i] + 1, lst[i] - 1, s[i]) / 2 << ' ';
	}
	cout << endl;
	//pause;
	return 0;
}


#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include <string>
#include <sstream>
#include <set>
#include <queue>
#include <map>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <bitset>
#include <stack>
#include <math.h>

#define en "\n"

using namespace std;
namespace patch
{
	template < typename T > std::string to_string(const T& n)
	{
		std::ostringstream stm;
		stm << n;
		return stm.str();
	}
}

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ld PI = 3.14159265358979323846;

struct Point
{
	double x, y;
};

ll gcd(ll a, ll b)
{
	return a == 0 ? b : gcd(b % a, a);
}

bool isAPrime(long long m)
{
	for (long long p = 2; p * p <= m; p++)
	{
		if (m % p == 0) { return false; }
	}
	return true;
}

ll mdf = 1e+9 + 7;

long long binpow(long long a, long long n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return (binpow(a, n - 1) * a) % mdf;
	else {
		long long b = binpow(a, n / 2) % mdf;
		return (b * b) % mdf;
	}
}

int count_setbits(int N)
{
	int cnt = 0;

	while (N > 0)
	{
		cnt += (N & 1);
		N = N >> 1;
	}

	return cnt;

}

ll phi(ll n) { //функция эйлера, вычисляет кол-во чисел взаимнопростых c n
	ll result = n;
	for (ll i = 2; i * i <= n; ++i)
		if (n % i == 0) {
			while (n % i == 0)
				n /= i;
			result -= result / i;
		}
	if (n > 1)
		result -= result / n;
	return result;
}

bool compare(pair<int, ll> a, pair<int, ll> b)
{
	return a.second < b.second;
}

int mergethem(vector<int>& a, int l, int m, int r)
{
	int Inv = 0;

	vector<int> buff(r - l + 1);
	int pos1 = l, pos2 = m + 1, posB = 0;

	while (pos1 <= m && pos2 <= r)
	{
		if (a[pos1] < a[pos2])
		{
			buff[posB++] = a[pos1++];
		}
		else
		{
			Inv += m - pos1 + 1;
			buff[posB++] = a[pos2++];
		}
	}

	while (pos1 <= m)
		buff[posB++] = a[pos1++];

	while (pos2 <= r)
		buff[posB++] = a[pos2++];

	copy(buff.begin(), buff.end(), a.begin() + l);

	return Inv;
}

int mergesort(vector<int>& a, int l, int r)
{
	int curInv = 0;
	if (l == r)
		return curInv;

	int m = (l + r) / 2;

	curInv += mergesort(a, l, m);
	curInv += mergesort(a, m + 1, r);

	curInv += mergethem(a, l, m, r);

	return curInv;
}

vector<pair<int, int>> g[200005];
int in_v[200005], out_v[200005];
ll dist_to_root[200005];

int timer = 0;

void dfs(int p, ll cur_dist, int u)
{
	dist_to_root[u] = cur_dist;
	in_v[u] = timer++;

	for (auto pr : g[u])
	{
		int v = pr.first, price = pr.second;

		if (v == p) continue;
		dfs(u, cur_dist + price, v);
	}
	out_v[u] = timer++;
}

bool isParent(int u, int v) // v в поддереве u?
{
	return in_v[u] < in_v[v] && out_v[u] > out_v[v];
}

void solve()
{
	int n; cin >> n;
	vector<int> num_v(n);
	vector<int> ans(n);
	for (int i = 0; i < n; i++) cin >> num_v[i];

	for (int v = 1; v < n; v++)
	{
		int u; cin >> u; u--;
		int p; cin >> p;
		g[u].push_back({ v,p });
	}

	dfs(-1, 0, 0);

	//cout << isParent(2, 4) << en;

	for (int u = 0; u < n; u++)
	{
		for (int v = 0; v < n; v++)
			if (isParent(u, v))
			{
				int du = dist_to_root[u], dv = dist_to_root[v];

				if (dv - du <= num_v[v]) ans[u]++;
			}
	}

	for (int i = 0; i < n; i++) cout << ans[i] << " ";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int q = 1;
	//cin >> q;
	while (q--) solve();

	return 0;
}


#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include <string>
#include <sstream>
#include <set>
#include <queue>
#include <map>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <bitset>
#include <stack>
#include <math.h>

#define en "\n"

using namespace std;
namespace patch
{
	template < typename T > std::string to_string(const T& n)
	{
		std::ostringstream stm;
		stm << n;
		return stm.str();
	}
}

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ld PI = 3.14159265358979323846;

struct Point
{
	double x, y;
};

ll gcd(ll a, ll b)
{
	return a == 0 ? b : gcd(b % a, a);
}

bool isAPrime(long long m)
{
	for (long long p = 2; p * p <= m; p++)
	{
		if (m % p == 0) { return false; }
	}
	return true;
}

ll mdf = 1e+9 + 7;

long long binpow(long long a, long long n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return (binpow(a, n - 1) * a) % mdf;
	else {
		long long b = binpow(a, n / 2) % mdf;
		return (b * b) % mdf;
	}
}

int count_setbits(int N)
{
	int cnt = 0;

	while (N > 0)
	{
		cnt += (N & 1);
		N = N >> 1;
	}

	return cnt;

}

ll phi(ll n) { //функция эйлера, вычисляет кол-во чисел взаимнопростых c n
	ll result = n;
	for (ll i = 2; i * i <= n; ++i)
		if (n % i == 0) {
			while (n % i == 0)
				n /= i;
			result -= result / i;
		}
	if (n > 1)
		result -= result / n;
	return result;
}

bool compare(pair<int, ll> a, pair<int, ll> b)
{
	return a.second < b.second;
}

int mergethem(vector<int>& a, int l, int m, int r)
{
	int Inv = 0;

	vector<int> buff(r - l + 1);
	int pos1 = l, pos2 = m + 1, posB = 0;

	while (pos1 <= m && pos2 <= r)
	{
		if (a[pos1] < a[pos2])
		{
			buff[posB++] = a[pos1++];
		}
		else
		{
			Inv += m - pos1 + 1;
			buff[posB++] = a[pos2++];
		}
	}

	while (pos1 <= m)
		buff[posB++] = a[pos1++];

	while (pos2 <= r)
		buff[posB++] = a[pos2++];

	copy(buff.begin(), buff.end(), a.begin() + l);

	return Inv;
}

int mergesort(vector<int>& a, int l, int r)
{
	int curInv = 0;
	if (l == r)
		return curInv;

	int m = (l + r) / 2;

	curInv += mergesort(a, l, m);
	curInv += mergesort(a, m + 1, r);

	curInv += mergethem(a, l, m, r);

	return curInv;
}

vector<pair<int, int>> g[200005];
ll dist_to_root[200005];
int num_v[200005];

vector<int> parents_in_path;

int parent[200005];

int part_sums[200005];

void dfs(int u, int p, ll cur_dist)
{
	dist_to_root[u] = cur_dist;
	parents_in_path.push_back(u);

	int l = -1, r = parents_in_path.size() - 1;

	while (r - l > 1)
	{
		int m = (l + r) / 2;

		//найти первого предка для к-го не выполняется усл-е
		int v = parents_in_path[m];
		if (dist_to_root[u] - dist_to_root[v] <= num_v[u])
			r = m;
		else l = m;
	}

	// что-то с суммами на отрезке ыыыы
	// r - первая вершина для которой не выполняется усл-е
	//cout << u << ": " << parent[u] << " " << parent[r] << en;
	part_sums[parent[u]]++; //начало отрезка
	part_sums[parent[parents_in_path[r]]]--; //конец

	for (auto pr : g[u])
	{
		int v = pr.first, price = pr.second;

		if (v == p) continue;
		dfs(v, u, cur_dist + price);
	}

	parents_in_path.pop_back();
}

void upd_answers(int u, int p)
{
	for (auto pr : g[u])
	{
		int v = pr.first;

		if (v == p) continue;
		upd_answers(v, u);
		part_sums[u] += part_sums[v];
	}
}

void solve()
{
	int n; cin >> n;

	vector<int> ans(n);
	for (int i = 1; i <= n; i++) cin >> num_v[i];

	for (int v = 2; v <= n; v++)
	{
		int u; cin >> u;
		int p; cin >> p;
		g[u].push_back({ v,p });

		parent[v] = u;
	}

	dfs(1, -1, 0);
	upd_answers(1, -1);

	for (int i = 1; i <= n; i++) cout << part_sums[i] << " ";
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int q = 1;
	//cin >> q;
	while (q--) solve();

	return 0;
}


#include<bits/stdc++.h>
#define In_the_name_of_allah_the_merciful ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Alhamdulillah return 0;
#define pb push_back
#define ins(x) insert(x)
#define fi first
#define se second
#define ub upper_bound
#include<bits/stdc++.h>
#define In_the_name_of_allah_the_merciful ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Alhamdulillah return 0;
#define pb push_back
#define ins(x) insert(x)
#define fi first
#define se second
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define sz(v) ((ll)((v).size()))
#define reset(v,val) memset(v,val,sizeof(v))
#define erep(i, x, n) for ( i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for( i = x; i<(ll)(n); i++)
using namespace std;
typedef   long long  int    ll;
long long int mod=1e9+7;
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll m=0,n,res,k,ans=0,nbcycle=0;
string s2="zero",ch="",s,t,s1="";
set< pair<ll,ll>  > st;
vector< pair<string,ll> >vm;
vector< pair< ll, pair<ll,ll> > > vvv;
vector<pair<ll,ll> >vv,vv2;
vector< pair<ll,ll>  > v[200005];
ll dp[200005]={0},a[200005],b[200005];
vector< pair<ll,ll> >vnode;
ll used[200005]={0},pos[200005],from[200005],to[200005];
ll sz=0;
/******************************/
void dfs(ll node) {
    used[node]=true;
    pos[node]=++sz;
    from[node]=sz;
    to[node]=sz;
    ll i;
    for(i=0;i<v[node].size();i++) {
        ll y=v[node][i].first;
        ll w=v[node][i].second;
        if(!used[y]) {
        	dp[y]=w+dp[node];
        	dfs(y);
			to[node]=max(to[node],to[y]);
		}
    }
}

vector<ll> tree[1000005];
/************************************************/
void build(ll node,ll start,ll end)
{
  	if(start==end){
		tree[node].push_back(a[start]);
    	}
		else{
		ll mid=(start+end)/2;
		build(2*node,start,mid);
		build(2*node+1,mid+1,end);
		merge(tree[2*node].begin(),tree[2*node].end(),tree[2*node+1].begin(),tree[2*node+1].end(),back_inserter(tree[node]));
	}
}
/***********************************************/
ll query(ll node,ll start,ll end,ll l,ll r,ll x)
{
    if(r<start or l>end)return 0;
    if(l<=start&&r>=end)return upper_bound(tree[node].begin(),tree[node].end(),x)-tree[node].begin();
    ll mid=(start+end)/2;
    ll left = query(2*node,start,mid,l,r,x);
    ll right = query(2*node+1,mid+1,end,l,r,x);
    return (left+right);
}

int main(){
In_the_name_of_allah_the_merciful

    ll i=0,x,z,y,j=0,q,mm=0,mx=-1e9,idx=0,ok=0,l=0,r=0,negatif=0,positif=0,l1,r1,d;
    set< pair<ll,ll> > ::iterator it,it1;
   // freopen("a.txt","r",stdin);
    cin>>n;
    for(i=1;i<=n;i++)cin>>b[i];
    for(i=1;i<n;i++){
        cin>>x>>z;
        v[x].pb({i+1,z});
        v[i+1].pb({x,z});
    }
    dfs(1);
	for(i=1;i<=n;i++)vnode.push_back({pos[i],i});
	sort(vnode.begin(),vnode.end());
	for(i=1;i<=n;i++)used[i]=vnode[i-1].second;
	for(i=1;i<=n;i++)dp[i]-=b[i];
	for(i=1;i<=n;i++)a[i]=dp[used[i]];
	build(1,1,n);
	for(i=1;i<=n;i++){
        l=from[i];
        r=to[i];
        ans=query(1,1,n,l,r,dp[i]+b[i])-1;
        cout<<ans<<'\n';
	}
Alhamdulillah
 }