#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 100;
int n;
pair<int, int> pri[MAXN];
vector<pair<int, int> > edge[MAXN];
int q[MAXN];
int head, tail;
int father[MAXN];
int res[MAXN];
int val[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &pri[i].first);
    pri[i].second = i;
  }
  sort(pri, pri + n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    --a, --b;
    edge[a].push_back(make_pair(b, c));
    edge[b].push_back(make_pair(a, c));
  }
  memset(father, -1, sizeof(father));
  q[0] = 0;
  head = 0;
  tail = 1;
  while (head < tail) {
    int now = q[head++];
    for (int i = 0; i < edge[now].size(); ++i) {
      int next = edge[now][i].first;
      if (next == father[now]) continue;
      father[next] = now;
      val[next] = edge[now][i].second;
      q[tail++] = next;
    }
  }
  res[0] = 0;
  vector<pair<int, int> > now;
  for (int i = 0; i < n; ++i) {
    if (pri[i].second == 0)
      continue;
    else
      now.push_back(make_pair(pri[i].second, pri[i].second));
  }
  int t = 0;
  while (!now.empty()) {
    ++t;
    vector<pair<int, int> > next;
    int vv[MAXN];
    memset(vv, 0, sizeof(vv));
    for (int i = 0; i < now.size(); ++i) {
      int cur = now[i].first;
      int place = now[i].second;
      if (vv[place] == val[place]) {
        next.push_back(now[i]);
        continue;
      }
      ++vv[place];
      if (father[place] == 0)
        res[cur] = t;
      else {
        next.push_back(make_pair(cur, father[place]));
      }
    }
    now = next;
  }
  for (int i = 0; i < n; ++i) {
    printf("%d%c", res[i], i == n - 1 ? '\n' : ' ');
  }
  return 0;
}
