#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000 + 100;
int a[MAXN], N, e[MAXN][3], ans[MAXN];
vector<int> d[MAXN];
vector<pair<int, int> > v[MAXN];
bool is[MAXN];
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) return a.first < b.first;
  return ::a[a.second] < ::a[b.second];
}
void dfs(int a, int par, int cofpar) {
  is[a] = true;
  for (__typeof(((int)(d[a]).size())) i = (0); i < (((int)(d[a]).size()));
       ++i) {
    int k = d[a][i], p = e[k][0], nei = e[k][1];
    if (nei == a) swap(nei, p);
    if (!is[nei]) {
      dfs(nei, a, e[k][2]);
    }
  }
  if (a != 0) {
    v[par].push_back(pair<int, int>(1, a));
    sort(v[a].begin(), v[a].end(), cmp);
    for (__typeof(((int)(v[a]).size())) i = (0); i < (((int)(v[a]).size()));
         ++i) {
      int j = i;
      int k = 0;
      while (k < cofpar && i < ((int)(v[a]).size()) &&
             v[a][i].first == v[a][j].first) {
        v[par].push_back(pair<int, int>(v[a][i].first + 1, v[a][i].second));
        ++i;
        ++k;
      }
      if (i < ((int)(v[a]).size()) && v[a][i].first == v[a][j].first) {
        k = i;
        while (k < ((int)(v[a]).size()) && v[a][k].first == v[a][i - 1].first) {
          ++v[a][k].first;
          ++k;
        }
        j = k;
        while (k < ((int)(v[a]).size()) && v[a][k].first == v[a][i].first) ++k;
        vector<pair<int, int> > newv(k - i);
        merge(v[a].begin() + i, v[a].begin() + j, v[a].begin() + j,
              v[a].begin() + k, newv.begin(), cmp);
        for (__typeof(k) s = (i); s < (k); ++s) v[a][s] = newv[s - i];
      }
      --i;
    }
  } else {
    ans[0] = 0;
    for (__typeof(((int)(v[0]).size())) i = (0); i < (((int)(v[0]).size()));
         ++i) {
      ans[v[0][i].second] = v[0][i].first;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N;
  for (__typeof(N) i = (0); i < (N); ++i) cin >> a[i];
  for (__typeof(N) i = (1); i < (N); ++i) {
    cin >> e[i][0] >> e[i][1] >> e[i][2];
    --e[i][0];
    --e[i][1];
    d[e[i][0]].push_back(i);
    d[e[i][1]].push_back(i);
  }
  dfs(0, 0, 1);
  for (__typeof(N) i = (0); i < (N); ++i) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
