#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 1;
struct edge {
  int u, v, c;
  friend bool operator<(const edge& p1, const edge& p2) { return p1.u < p2.u; }
};
int n;
int cnt[maxn][maxn];
int last[maxn][maxn];
int pri[maxn];
int ord[maxn];
int fa[maxn][2];
edge es[maxn + maxn];
int cnte;
int idx[maxn];
bool mycmp(int x, int y) { return pri[x] < pri[y]; }
void dfs1(int x, int f, int c) {
  fa[x][0] = f;
  fa[x][1] = c;
  for (int j = idx[x]; j < idx[x + 1]; j++)
    if (es[j].v != f) dfs1(es[j].v, x, es[j].c);
}
int findnear(int x, int pos) {
  if (last[x][pos] != pos) last[x][pos] = findnear(x, last[x][pos]);
  return last[x][pos];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &pri[i]);
    ord[i] = i;
  }
  sort(ord, ord + n, mycmp);
  cnte = 0;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &es[cnte].u, &es[cnte].v, &es[cnte].c);
    es[cnte].u--;
    es[cnte].v--;
    cnte++;
    es[cnte] = es[cnte - 1];
    swap(es[cnte].u, es[cnte].v);
    cnte++;
  }
  sort(es, es + cnte);
  for (int i = 0, j = 0; i < n; i++) {
    while (j < cnte && es[j].u < i) j++;
    idx[i] = j;
  }
  idx[n] = cnte;
  dfs1(0, -1, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cnt[i][j] = 0;
      last[i][j] = j;
    }
  }
  for (int i = 0; i < n; i++) {
    int x = ord[i];
    int tt = 0;
    int cur = x;
    while (cur != 0) {
      tt = findnear(cur, tt);
      cnt[cur][tt]++;
      if (cnt[cur][tt] >= fa[cur][1])
        last[cur][tt] = findnear(cur, last[cur][tt] + 1);
      tt++;
      cur = fa[cur][0];
    }
    pri[x] = tt;
  }
  for (int i = 0; i < n; i++) {
    i&& printf(" ");
    printf("%d", pri[i]);
  }
  puts("");
  return 0;
}
