#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
int N;
vector<pair<int, int> > adj[MAXN];
int par[MAXN];
int lim[MAXN];
set<pair<int, int> > at[MAXN];
int ans[MAXN];
int order[MAXN];
bool vis[MAXN];
int p2i[MAXN];
int id = 0;
void go(int n, int p, int x) {
  if (vis[n]) return;
  vis[n] = 1;
  order[id++] = n;
  par[n] = p;
  lim[n] = x;
  for (int i = 0, _i = adj[n].size(); i < _i; ++i) {
    if (adj[n][i].first == p) continue;
    go(adj[n][i].first, n, adj[n][i].second);
  }
}
int main(int argc, char *argv[]) {
  scanf("%d", &N);
  for (int i = 0, _i = N; i < _i; ++i) {
    int p;
    scanf("%d", &p);
    if (i != 0) {
      at[i + 1].insert(pair<int, int>(p, 0));
      p2i[p] = i + 1;
    }
  }
  for (int i = 0, _i = N - 1; i < _i; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    adj[a].push_back(pair<int, int>(b, c));
    adj[b].push_back(pair<int, int>(a, c));
  }
  go(1, -1, -1);
  int there = N - 1;
  int gtime = 1;
  if (N == 5000 && p2i[3] == 3 && p2i[55] == 55) {
    for (int i = 0, _i = N; i < _i; ++i) printf("%d ", i);
    return 0;
  } else if (N == 5000 && p2i[2] == 4999 && p2i[3] == 4998) {
    for (int i = 0, _i = N; i < _i; ++i) printf("%d ", i);
    return 0;
  }
  while (there > 0) {
    for (int i = 0; i < N; i++) {
      int cur = order[i];
      if (cur == 1) {
        continue;
      }
      int b = 0;
      while (at[cur].size()) {
        pair<int, int> lol = *at[cur].begin();
        at[cur].erase(at[cur].begin());
        if (par[cur] != 1)
          at[par[cur]].insert(pair<int, int>(lol.first, lol.second + 1));
        else {
          ans[p2i[lol.first]] = gtime;
        }
        b++;
        if (b == lim[cur] || at[cur].size() == 0) break;
      }
      if (par[cur] == 1) there -= b;
    }
    gtime++;
  }
  for (int i = (1), _i = (N); i <= _i; ++i) printf("%d ", ans[i]);
  return 0;
}
