#include <bits/stdc++.h>
using namespace std;
int n, t, x, y, w;
int pri[5005], a[5005], l[5005], qd[5005 + 5005], qn[5005 + 5005],
    qc[5005 + 5005], par[5005], cap[5005], ret[5005];
short int cnt[5005][5005];
void dfs(int x, int y) {
  for (int i = l[x]; i; i = qn[i]) {
    if (qd[i] == y) continue;
    dfs(qd[i], x);
    par[qd[i]] = x;
    cap[qd[i]] = qc[i];
  }
}
void bd(int x, int y, int w) {
  qd[++t] = y, qn[t] = l[x], l[x] = t;
  qc[t] = w;
}
bool cmp(int x, int y) { return pri[x] < pri[y]; }
int main() {
  scanf("%d", &n);
  for (int i = (1); i <= (int)(n); i++) scanf("%d", &pri[i]), a[i] = i;
  for (int i = (1); i < (int)(n); i++) {
    scanf("%d%d%d", &x, &y, &w);
    bd(x, y, w);
    bd(y, x, w);
  }
  dfs(1, 0);
  sort(a + 1, a + n + 1, cmp);
  for (int i = (1); i <= (int)(n); i++) {
    x = a[i];
    t = 0;
    while (x != 1) {
      while (cnt[x][t] == cap[x]) t++;
      cnt[x][t]++;
      x = par[x];
      t++;
    }
    ret[a[i]] = t;
  }
  for (int i = (1); i <= (int)(n); i++)
    printf("%d%c", ret[i], i < n ? ' ' : '\n');
  return 0;
}
