1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define VAR(v,w) __typeof(w) v=(w)
#define FORE(it,c) for(VAR(it,(c).begin());it!=(c).end();++it)
#define PB push_back
#define INT(x) int x; scanf("%d", &x)
#define LLG(x) LL x; scanf("%lld", &x)

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;

LL r[100000], c[200000];
int t[200000];
VVI g;
bool u[100000];
queue<int>* qq;

void go(int v, int p, LL b) {
	if (b < 0) return;
	if (!u[v]) {
		u[v] = 1;
		qq->push(v);
	}
	FORE(it,g[v]) {
		int w = t[*it];
		if (w == p) continue;
		go(w, v, b - c[*it]);
	}
}

int main() {
	INT(n);
	REP(i,n) scanf("%lld", &r[i]);
	g.resize(n);
	int m = 0;
	REP(i,n-1) {
		INT(a);
		INT(b);
		LLG(cc);
		--a;
		--b;
		t[m] = b;
		c[m] = cc;
		g[a].PB(m++);
		t[m] = a;
		c[m] = cc;
		g[b].PB(m++);
	}
	REP(i,n) {
		if (i) printf(" ");
		REP(j,n) u[j] = 0;
		queue<int> q;
		qq = &q;
		u[i] = 1;
		q.push(i);
		while (!q.empty()) {
			int v = q.front();
			q.pop();
			go(v, -1, r[v]);
		}
		int res = 0;
		REP(j,n) if (u[j]) ++res;
		printf("%d", res);
	}
	printf("\n");
}