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
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005
using namespace std;

struct sas
{
	int u;
	ll c;
};
vector <sas> g[maxn];
ll r[maxn];

vector <int> dost[maxn];

int start;
int v[maxn], l;
void dfs(int w, ll odl)
{
	v[w] = l;
	dost[start].emplace_back(w);
	for(sas i : g[w]) if(v[i.u] < l && odl >= i.c) dfs(i.u, odl-i.c);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> r[i];
	
	for(int i = n; --i;)
	{
		int a, b;
		ll c;
		cin >> a >> b >> c;
		g[a].push_back({b, c});
		g[b].push_back({a, c});
	}
	
	for(start = 1; start <= n; ++start) ++l, dfs(start, r[start]);
	
	for(int i = 1; i <= n; ++i)
	{
		int wyn = 1;
		queue <int> q;
		q.push(i);
		++l;
		v[i] = l;
		while(!q.empty())
		{
			int w = q.front();
			q.pop();
			for(int j : dost[w]) if(v[j] < l)
			{
				v[j] = l, ++wyn, q.push(j);
				if(wyn == n) break;
			}
			if(wyn == n) break;
		}
		cout << wyn << " ";
	}
	
	return 0;
}