#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
struct node {
  int id;
  int priority;
};
struct cmp {
  bool operator()(node x, node y) { return x.priority > y.priority; }
};
int g[maxn][maxn];
priority_queue<node, vector<node>, cmp> v[maxn];
int p[maxn];
int f[maxn];
int t[maxn];
int d[maxn];
bool visit[maxn];
int n;
int dd;
void dfs(int u) {
  visit[u] = true;
  for (int i = 1; i <= n; i++) {
    if (g[u][i] != 0 && visit[i] == false) {
      f[i] = u;
      d[++dd] = i;
      dfs(i);
    }
  }
}
void work() {
  int i, c, num, tt;
  memset(t, 0, sizeof(t));
  bool flag = true;
  tt = 0;
  while (flag) {
    tt++;
    flag = false;
    for (int k = 1; k <= dd; k++) {
      i = d[k];
      c = g[i][f[i]];
      num = 0;
      while (!v[i].empty() && num < c) {
        flag = true;
        num++;
        if (f[i] == 1) {
          t[v[i].top().id] = tt;
          v[i].pop();
          continue;
        }
        v[f[i]].push(v[i].top());
        v[i].pop();
      }
    }
  }
  for (i = 1; i <= n; i++) printf("%d ", t[i]);
  printf("\n");
}
int main() {
  int i, a, b, c;
  node s;
  while (scanf("%d", &n) != EOF) {
    memset(g, 0, sizeof(g));
    for (i = 1; i <= n; i++) {
      s.id = i;
      scanf("%d", &s.priority);
      v[i].push(s);
    }
    for (i = 1; i <= n - 1; i++) {
      scanf("%d%d%d", &a, &b, &c);
      g[a][b] = c;
      g[b][a] = c;
    }
    memset(visit, false, sizeof(visit));
    dd = 0;
    dfs(1);
    work();
  }
  return 0;
}
