#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 400010;
int n;
int f[5005], a[5005], b[5005], ans[5005], c[5005];
int ti[5005][5005];
vector<pair<int, int> > G[5005];
void dfs(int u, int fa, int cap) {
  f[u] = fa;
  c[u] = cap;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i].first;
    if (v == fa) continue;
    dfs(v, u, G[u][i].second);
  }
}
void work(int st, int id, int time) {
  if (id == 1) {
    ans[st] = time;
    return;
  }
  while (ti[id][time] == c[id]) {
    time++;
  }
  ti[id][time]++;
  work(st, f[id], time + 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) b[i] = a[i];
  sort(b + 1, b + 1 + n);
  for (int i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + 1 + n, a[i]) - b;
  for (int i = 1; i <= n; i++) b[i] = a[i];
  for (int i = 1; i <= n; i++) a[b[i]] = i;
  for (int i = 1; i < n; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    G[u].push_back(pair<int, int>(v, w));
    G[v].push_back(pair<int, int>(u, w));
  }
  dfs(1, -1, 0);
  for (int i = 1; i <= n; i++) {
    work(a[i], a[i], 0);
  }
  for (int i = 1; i <= n; i++) {
    printf("%d", ans[i]);
    if (i != n)
      printf(" ");
    else
      printf("\n");
  }
  return 0;
}
