#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5010;
int A[MAXN];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pqs[MAXN];
vector<pair<int, int> > conn[MAXN];
int par[MAXN];
int cap[MAXN];
int ans[MAXN];
void dfs(int cur, int prv, int c) {
  par[cur] = prv;
  cap[cur] = c;
  for (typeof((conn[cur]).begin()) i = (conn[cur]).begin(),
                                   _i = (conn[cur]).end();
       i != _i; ++i) {
    if (i->first != prv) {
      dfs(i->first, cur, i->second);
    }
  }
}
int cnt = 1;
int nottime = 0;
void go(int n) {
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > > &pq = pqs[n];
  int up = par[n];
  for (int i = 0; !pq.empty() && i < cap[n]; ++i) {
    int nxt = pq.top().second;
    pq.pop();
    if (up == 1) {
      ans[nxt] = nottime;
      ++cnt;
    } else {
      pqs[up].push(pair<int, int>(A[nxt], nxt));
    }
  }
  for (typeof((conn[n]).begin()) i = (conn[n]).begin(), _i = (conn[n]).end();
       i != _i; ++i) {
    if (i->first != up) {
      go(i->first);
    }
  }
}
int N;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", A + i);
  }
  for (int i = 1; i < N; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    conn[a].push_back(pair<int, int>(b, c));
    conn[b].push_back(pair<int, int>(a, c));
  }
  dfs(1, 0, 0);
  for (int i = 2; i <= N; ++i) {
    pqs[i].push(pair<int, int>(A[i], i));
  }
  while (cnt < N) {
    ++nottime;
    go(1);
  }
  for (int i = 1; i <= N; ++i) {
    if (i != 1) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}
