#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
map<int, int> val;
int pri[maxn];
priority_queue<int> pq[maxn];
int ndx[maxn], en = 0;
struct EDGE {
  int to, cap, next;
} e[maxn * 2];
int n, reach, t;
int ans[maxn];
void add_edge(int x, int y, int c) {
  en++;
  e[en].to = y;
  e[en].cap = c;
  e[en].next = ndx[x];
  ndx[x] = en;
}
void DFS(int x, int parent, int cap) {
  int i, cur;
  for (i = 0; i < cap; i++) {
    if (pq[x].size() == 0) break;
    cur = pq[x].top();
    pq[x].pop();
    if (x == 1) {
      ans[val[-cur]] = t;
      reach++;
    } else
      pq[parent].push(cur);
  }
  for (i = ndx[x]; i != 0; i = e[i].next)
    if (e[i].to != parent) DFS(e[i].to, x, e[i].cap);
}
int main() {
  int i, x, y, c;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &pri[i]);
    val[pri[i]] = i;
    pq[i].push(-pri[i]);
  }
  for (i = 1; i < n; i++) {
    scanf("%d%d%d", &x, &y, &c);
    add_edge(x, y, c);
    add_edge(y, x, c);
  }
  reach = 0;
  for (t = 0; t < n; t++) {
    DFS(1, 0, n);
    if (reach == n) break;
  }
  for (i = 1; i <= n; i++)
    if (i == n)
      printf("%d\n", ans[i]);
    else
      printf("%d ", ans[i]);
  return 0;
}
