#include <bits/stdc++.h>
using namespace std;
int read() {
  int ans = 0;
  char last = ' ', ch = getchar();
  while (ch < '0' || ch > '9') last = ch, ch = getchar();
  while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
  if (last == '-') ans = -ans;
  return ans;
}
const int maxn = 5009, maxm = 1e4 + 8;
int p[maxn];
struct node {
  node() {}
  node(int id) : id(id) {}
  int id;
  bool operator<(const node &rhs) const { return p[id] > p[rhs.id]; }
};
priority_queue<node> Q[maxn];
int head[maxn], nex[maxm], to[maxm], val[maxm], now;
void add(int a, int b, int v) {
  nex[++now] = head[a];
  head[a] = now;
  to[now] = b;
  val[now] = v;
}
int tot = 1;
int ans[maxn];
int ct = 0;
int vis[maxn];
bool dfs(int p, int f) {
  int h = 0;
  for (int i = head[p]; i; i = nex[i]) {
    int u = to[i];
    if (u == f || vis[u]) continue;
    int ttt = val[i];
    while (ttt && !Q[u].empty()) {
      ttt--;
      node tmp = Q[u].top();
      Q[u].pop();
      Q[p].push(tmp);
      if (p == 1) ans[tmp.id] = ct, tot++;
    }
    bool have = dfs(u, p);
    if (!have)
      vis[u] = 1;
    else
      h = 1;
  }
  if (!Q[p].empty()) h = 1;
  return h;
}
int main() {
  int n = read();
  for (register int i = 1; i <= n; i++) {
    p[i] = read();
    Q[i].push(node(i));
  }
  for (register int i = 1; i <= n - 1; i++) {
    int a = read(), b = read(), v = read();
    add(a, b, v);
    add(b, a, v);
  }
  ans[1] = 0;
  while (tot < n) {
    ct++;
    dfs(1, -1);
  }
  for (register int i = 1; i <= n; i++) {
    printf("%d%c", ans[i], (i == n ? '\n' : ' '));
  }
}
