#include <bits/stdc++.h>
using namespace std;
int N;
struct Node {
  int x, next, c;
} edge[10000 + 4];
int edgenum, head[5000 + 5];
void AddEdge(int x, int y, int c) {
  edge[edgenum].x = y;
  edge[edgenum].next = head[x];
  edge[edgenum].c = c;
  head[x] = edgenum++;
}
int fa[5000 + 5], fc[5000 + 5], visted[5000 + 5];
void dfs(int x) {
  visted[x] = 1;
  for (int i = head[x]; i != -1; i = edge[i].next) {
    if (visted[edge[i].x]) continue;
    fa[edge[i].x] = x;
    fc[edge[i].x] = edge[i].c;
    dfs(edge[i].x);
  }
}
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    T[5000 + 5];
int day[5000 + 5];
void dfs2(int x) {
  int cnt = 0;
  if (x != 1) {
    while (cnt < fc[x] && T[x].empty() == false) {
      T[fa[x]].push(T[x].top());
      T[x].pop();
      cnt++;
    }
  }
  for (int i = head[x]; i != -1; i = edge[i].next) {
    if (edge[i].x == fa[x]) continue;
    dfs2(edge[i].x);
  }
}
int main() {
  scanf("%d", &N);
  memset(head, -1, sizeof(head));
  for (int i = 1, x; i <= N; i++) {
    scanf("%d", &x);
    T[i].push(pair<int, int>(x, i));
  }
  for (int i = 0, x, y, c; i + 1 < N; i++) {
    scanf("%d %d %d", &x, &y, &c);
    AddEdge(x, y, c);
    AddEdge(y, x, c);
  }
  dfs(1);
  {}
  memset(day, -1, sizeof(day));
  int cnt = 0;
  for (int i = 1; i <= 5000 && cnt < N; i++) {
    while (!T[1].empty()) {
      cnt++;
      pair<int, int> temp = T[1].top();
      day[temp.second] = i - 1;
      T[1].pop();
    }
    dfs2(1);
  }
  for (int i = 1; i <= N; i++) printf("%d%c", day[i], i == N ? '\n' : ' ');
  return 0;
}
