#include <bits/stdc++.h>
using namespace std;
int n;
int ax[5005];
pair<int, int> px[5005];
vector<pair<int, int> > vx[5005];
map<int, int> mp;
void dfs(int x, int p) {
  for (int i = 0; i < vx[x].size(); ++i) {
    int nx = vx[x][i].first;
    int ct = vx[x][i].second;
    if (nx != p) {
      px[nx] = make_pair(x, ct);
      dfs(nx, x);
    }
  }
}
vector<int> ct[5005];
vector<int> pr[5005];
bool done() {
  for (int i = 1; i <= n; ++i)
    if (ct[i].size() != 0) return false;
  return true;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> ax[i];
  for (int i = 1; i < n; ++i) {
    int u, v, x;
    cin >> u >> v >> x;
    vx[u].push_back(make_pair(v, x));
    vx[v].push_back(make_pair(u, x));
  }
  dfs(1, -1);
  for (int i = 1; i <= n; ++i) ct[i].push_back(ax[i]);
  int t = 0;
  while (!done()) {
    for (int i = 1; i <= n; ++i) {
      pr[i] = ct[i];
      ct[i].clear();
      sort(pr[i].begin(), pr[i].end());
    }
    if (pr[1].size()) {
      for (int i = 0; i < pr[1].size(); ++i) mp[pr[1][i]] = t;
    }
    for (int i = 2; i <= n; ++i) {
      if (pr[i].size() && px[i].first != -1) {
        for (int j = 0; j < px[i].second && j < pr[i].size(); ++j) {
          ct[px[i].first].push_back(pr[i][j]);
        }
        if (pr[i].size() > px[i].second)
          for (int j = px[i].second; j < pr[i].size(); ++j)
            ct[i].push_back(pr[i][j]);
      }
    }
    t++;
  }
  for (int i = 1; i <= n; ++i) cout << mp[ax[i]] << " ";
  cout << endl;
  return 0;
}
