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
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int MAXN = 2005;

vector<pair<int, ll>> g[MAXN];
ll r[MAXN];
int vis[MAXN], boomed[MAXN];
ll dist[MAXN][MAXN];
int32_t main() {
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> r[i];
    }

    for (int i = 1; i < n; i++) {
        ll a, b, w;
        cin >> a >> b >> w;
        g[a].push_back({b, w});
        g[b].push_back({a, w});
    }

    for (int i = 1; i <= n; i++) {
        queue<int> q;
        q.push(i);
        vis[i] = i;
        dist[i][i] = 0;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (auto u : g[v]) {
                if (vis[u.first] != i) {
                    vis[u.first] = i;
                    dist[i][u.first] = dist[i][v] + u.second;
                    q.push(u.first);
                }
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        queue<int> q;
        q.push(i);
        int booms = 1;
        boomed[i] = i;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (int j = 1; j <= n; j++) {
                if (boomed[j] != i && dist[v][j] <= r[v]) {
                    booms++;
                    boomed[j] = i;
                    q.push(j);
                }
            }
        }
        cout << booms << " ";
    }

    cout << "\n";
}