#include <bits/stdc++.h>
using namespace std;
int fa[5005], cap[5005];
struct node {
  int y, w, next;
} path[5005 * 2];
int first[5005], p;
inline void add(int x, int y, int w) {
  path[p].y = y;
  path[p].w = w;
  path[p].next = first[x];
  first[x] = p++;
}
int cc[5005][5005], ans[5005];
struct pri {
  int p, id;
  friend bool operator<(pri a, pri b) { return a.p < b.p; }
} pp[5005];
int n;
void dfs(int x, int r) {
  int y;
  for (int i = first[x]; i; i = path[i].next) {
    y = path[i].y;
    if (y == r) continue;
    fa[y] = x;
    cap[y] = path[i].w;
    dfs(y, x);
  }
}
int main() {
  while (scanf("%d", &n) != EOF) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &pp[i].p);
      pp[i].id = i;
      first[i] = 0;
    }
    p = 1;
    int x, y, w;
    for (int i = 1; i < n; i++) {
      scanf("%d %d %d", &x, &y, &w);
      add(x, y, w);
      add(y, x, w);
    }
    dfs(1, 0);
    sort(pp + 1, pp + 1 + n);
    ans[1] = 0;
    for (int i = 1; i <= n; i++) {
      int t = 0, f = pp[i].id;
      while (f != 1) {
        while (cc[f][t] >= cap[f]) t++;
        cc[f][t]++;
        t++;
        f = fa[f];
      }
      ans[pp[i].id] = t;
    }
    for (int i = 1; i <= n; i++) printf("%d%c", ans[i], i == n ? '\n' : ' ');
  }
  return 0;
}
