#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > g[5005];
int ans[5005];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq[5005];
void dfs(int u, int p, int d) {
  for (auto f : g[u]) {
    int v = f.first;
    int sz = f.second;
    if (v != p) {
      while (!pq[v].empty() and sz) {
        if (u == 1) {
          ans[pq[v].top().second] = d;
          pq[v].pop();
        } else {
          pq[u].push(pq[v].top());
          pq[v].pop();
        }
        sz--;
      }
      dfs(v, u, d);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    pq[i].push({x, i});
  }
  for (int i = 1; i <= n - 1; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    g[u].push_back({v, c});
    g[v].push_back({u, c});
  }
  ans[1] = 0;
  for (int i = 1; i <= n; i++) {
    dfs(1, 0, i);
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << ' ';
  }
  return 0;
}
