#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > prq[2][5002];
vector<pair<int, int> > adj[5002];
int par[5002], c[5002], ans[5002];
bool mark[5002];
map<int, int> mp;
void dfs(int nd) {
  mark[nd] = true;
  for (int i = 0; i < (int)adj[nd].size(); i++) {
    int ch = adj[nd][i].first;
    if (mark[ch]) continue;
    par[ch] = nd;
    c[ch] = adj[nd][i].second;
    dfs(ch);
  }
}
int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < (int)N; i++) {
    int p;
    scanf("%d", &p);
    mp[p] = i + 1;
    prq[0][i + 1].push(p);
  }
  for (int i = 0; i < (int)N - 1; i++) {
    int u, v, w;
    scanf("%d%d", &u, &v);
    scanf("%d", &w);
    adj[u].push_back(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }
  dfs(1);
  int day = 0, tot = 1, nw = 0;
  ans[1] = 0;
  while (1) {
    if (tot == N) break;
    for (int i = 2; i < (int)N + 1; i++) {
      int x = c[i];
      while (x > 0 && !prq[nw][i].empty()) {
        int nd = prq[nw][i].top();
        prq[nw][i].pop();
        if (par[i] == 1) {
          ans[mp[nd]] = day + 1;
          tot++;
        } else
          prq[nw ^ 1][par[i]].push(nd);
        x--;
      }
      if (!prq[nw][i].empty()) prq[nw ^ 1][i] = prq[nw][i];
      while (!prq[nw][i].empty()) prq[nw][i].pop();
    }
    day++;
    nw ^= 1;
  }
  for (int i = 1; i < (int)N + 1; i++) {
    if (i > 1) printf(" ");
    printf("%d", ans[i]);
  }
  puts("");
  return 0;
}
