#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, m, fa[N], a[N][N], dis[N], ans[N], cap[N], id[N];
int b[N][N], ord[N], f[N];
bool cmp(int i, int j) { return id[i] < id[j]; }
void dfs(int x) {
  for (int i = 1; i <= a[x][0]; i++)
    if (a[x][i] != fa[x]) {
      fa[a[x][i]] = x;
      cap[a[x][i]] = b[x][i];
      dfs(a[x][i]);
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &id[i]);
    ord[i] = i;
  }
  memset(a, 0, sizeof(a));
  for (int i = 1; i < n; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    a[x][++a[x][0]] = y;
    b[x][a[x][0]] = z;
    a[y][++a[y][0]] = x;
    b[y][a[y][0]] = z;
  }
  memset(fa, 0, sizeof(fa));
  dfs(1);
  sort(ord + 1, ord + 1 + n, cmp);
  memset(ans, -1, sizeof(ans));
  ans[1] = 0;
  for (int i = 2; i <= n; i++) dis[i] = i;
  int t = 0;
  for (ans[0] = 1; ans[0] < n;) {
    t++;
    for (int i = 1; i <= n; i++) f[i] = 0;
    for (int i = 1; i <= n; i++)
      if (ans[ord[i]] == -1)
        if (f[dis[ord[i]]] < cap[dis[ord[i]]]) {
          f[dis[ord[i]]]++;
          dis[ord[i]] = fa[dis[ord[i]]];
          if (dis[ord[i]] == 1) {
            ans[0]++;
            ans[ord[i]] = t;
          }
        }
  }
  for (int i = 1; i < n; i++) printf("%d ", ans[i]);
  printf("%d\n", ans[n]);
  return 0;
}
