#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 10;
int n, m;
int a[MAXN], par[MAXN], c[MAXN], ans[MAXN];
vector<pair<int, int> > e[MAXN];
vector<int> e2[MAXN];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    Q[MAXN];
int cnt[MAXN];
void dfs(int u) {
  cnt[u] = 1;
  for (int i = 0; i < (e[u].size()); i++) {
    int v = e[u][i].first;
    if (cnt[v] == 0) {
      e2[u].push_back(v);
      par[v] = u;
      c[v] = e[u][i].second;
      Q[v].push(make_pair(a[v], v));
      dfs(v);
    }
  }
}
int res, tot = 0;
void dfs2(int u) {
  int tn = c[u], v;
  while (tn-- && !Q[u].empty()) {
    v = Q[u].top().second;
    Q[u].pop();
    if (par[u] == 0) {
      ++tot;
      ans[v] = res;
    } else
      Q[par[u]].push(make_pair(a[v], v));
  }
  int cc = 0;
  for (int i = 0; i < (e2[u].size()); i++) {
    v = e2[u][i];
    if (cnt[v] == 0) {
      cc = 1;
      dfs2(v);
    }
  }
  if (cc == 0 && Q[u].empty()) cnt[u] = 1;
}
int main() {
  cin >> n;
  for (int i = 0; i < (n); i++) cin >> a[i];
  for (int i = 0; i < (n - 1); i++) {
    int u, v, z;
    cin >> u >> v >> z;
    u--, v--;
    e[u].push_back(make_pair(v, z));
    e[v].push_back(make_pair(u, z));
  }
  memset(cnt, 0, sizeof(cnt));
  dfs(0);
  ans[0] = 0;
  tot = 1;
  memset(cnt, 0, sizeof(cnt));
  while (tot < n) {
    res++;
    dfs2(0);
  }
  for (int i = 0; i < (n); i++) printf("%d%c", ans[i], i == n - 1 ? '\n' : ' ');
}
