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
/*
    Zadanie: Miny
    Autor: Tomasz Kwiatkowski
*/

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;

const int MAXN = 1e5 + 7;
const int INF = 1e9 + 7;

vector<int> G[MAXN];
vector<pair<int, ll>> G0[MAXN];
bool vis[MAXN];
ll radius[MAXN];

void DFS(int v, int p, ll d, int s)
{
    if (d < 0) return;
    G[s].pb(v);
    for (auto [u, w] : G0[v]) {
        if (u != p)
            DFS(u, v, d - w, s);
    }
}

int cnt_DFS(int v)
{
    int res = 1;
    vis[v] = true;
    for (auto u : G[v]) {
        if (!vis[u])
            res += cnt_DFS(u);
    }
    return res;
}

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

    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> radius[i];
    for (int i = 1; i < n; ++i) {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        G0[a].pb({b, c});
        G0[b].pb({a, c});
    }
    for (int v = 1; v <= n; ++v)
        DFS(v, v, radius[v], v);

    for (int v = 1; v <= n; ++v) {
        fill(vis, vis+n+1, 0);
        cout << cnt_DFS(v) << ' ';
    }
    cout << '\n';
    return 0;
}