#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
const int M = 55;
const int K = 200010;
const int LIT = 2500;
const int INF = 1 << 30;
const int dir[6][2] = {{2, 0}, {-2, 0}, {1, 1}, {-1, 1}, {1, -1}, {-1, -1}};
int n, res[N];
pair<int, int> fa[N];
priority_queue<int, vector<int>, greater<int> > que[N];
vector<pair<int, int> > rd[N];
map<int, int> place;
void dfs(int u, int f, int cp) {
  fa[u] = make_pair(f, cp);
  int s = rd[u].size();
  for (int i = 0; i < s; i++) {
    int v = rd[u][i].first;
    if (fa[v].first) continue;
    dfs(v, u, rd[u][i].second);
  }
}
void init() {
  memset(res, 0, sizeof(res));
  memset(fa, 0, sizeof(fa));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    place[x] = i;
    que[i].push(x);
  }
  for (int i = 1; i < n; i++) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    rd[u].push_back(make_pair(v, c));
    rd[v].push_back(make_pair(u, c));
  }
  dfs(1, -1, -1);
}
void dfs2(int u) {
  int to = fa[u].first, cp = fa[u].second;
  for (int i = 1; i <= cp && !que[u].empty(); i++) {
    int x = que[u].top();
    que[u].pop();
    que[to].push(x);
  }
  int s = rd[u].size();
  for (int i = 0; i < s; i++) {
    int v = rd[u][i].first;
    if (fa[v].first != u) continue;
    dfs2(v);
  }
}
void solve() {
  int tmp = 0, cnt = 0;
  while (1) {
    while (!que[1].empty()) {
      int x = place[que[1].top()];
      res[x] = tmp;
      que[1].pop();
      cnt++;
    }
    if (cnt >= n) break;
    tmp++;
    dfs2(1);
  }
  for (int i = 1; i <= n; i++) printf("%d ", res[i]);
  printf("\n");
}
int main() {
  init();
  solve();
}
