#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
vector<pair<int, int> > e[maxn];
pair<int, int> a[maxn];
int here[maxn];
int f[maxn], c[maxn], d[maxn];
int ans[maxn];
int n;
void dfs(int u, int pa, int cost) {
  f[u] = pa;
  c[u] = cost;
  for (int i = 0; i < e[u].size(); ++i)
    if (e[u][i].first != pa) dfs(e[u][i].first, u, e[u][i].second);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i].first), a[i].second = i;
  for (int i = 1; i <= n; ++i) here[i] = i;
  sort(a + 1, a + 1 + n);
  for (int x, y, c, i = 1; i < n; ++i)
    scanf("%d%d%d", &x, &y, &c), e[x].push_back(make_pair(y, c)),
        e[y].push_back(make_pair(x, c));
  dfs(1, 0, 0);
  bool upd = true;
  while (upd) {
    upd = false;
    for (int i = 1; i <= n; ++i) d[i] = 0;
    for (int i = 1; i <= n; ++i)
      if (here[a[i].second] != 1) ans[a[i].second]++;
    for (int i = 1; i <= n; ++i)
      if (d[here[a[i].second]] < c[here[a[i].second]]) {
        upd = true;
        d[here[a[i].second]]++;
        here[a[i].second] = f[here[a[i].second]];
      }
  }
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
  return 0;
}
