#include <bits/stdc++.h>
using namespace std;
int G;
vector<pair<int, int> > wa;
vector<int> put[5005], tra[5005];
int cap[5005][5005];
int nxt[5005];
int num[5005][5005];
int re[5005];
int main() {
  scanf("%d", &G);
  for (int g = 1; g <= G; g++) {
    int pri;
    scanf("%d", &pri);
    wa.push_back(make_pair(pri, g));
  }
  int a, b, cnt;
  for (int d = 0; d < G - 1; d++) {
    scanf("%d%d%d", &a, &b, &cnt);
    put[a].push_back(b);
    cap[a][b] = cnt;
    put[b].push_back(a);
    cap[b][a] = cnt;
  }
  int cu = 1;
  list<int> li;
  li.push_back(cu);
  nxt[cu] = 1;
  while (!li.empty()) {
    cu = li.front();
    li.pop_front();
    for (int i = 0; i < put[cu].size(); i++) {
      int t = put[cu][i];
      if (!nxt[t]) {
        nxt[t] = cu;
        li.push_back(t);
      }
    }
  }
  sort(wa.begin(), wa.end());
  for (int d = 0; d < G; d++) {
    int t = wa[d].second, nt, ori = t;
    int day = 0;
    while (t != 1) {
      int nt = nxt[t];
      while (num[t][day] >= cap[t][nt]) {
        day++;
      }
      num[t][day]++;
      t = nt;
      day++;
    }
    re[ori] = day;
  }
  for (int g = 1; g <= G; g++) printf("%d ", re[g]);
}
