#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > g;
vector<priority_queue<int> > now;
int t = 0;
int num = 0;
void dfs(int u, int from) {
  for (int i = 0; i < ((int)g[u].size()); ++i) {
    int to = g[u][i].first;
    int c = g[u][i].second;
    if (to == from) continue;
    for (int j = 0; j < c; ++j) {
      if (now[to].empty()) break;
      int q = now[to].top();
      now[to].pop();
      now[u].push(q);
    }
    dfs(to, u);
  }
}
int main() {
  int n;
  cin >> n;
  map<int, int> ind;
  vector<int> a(n);
  now.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    a[i] *= -1;
    ind[a[i]] = i;
    now[i].push(a[i]);
  }
  g.resize(n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, c;
    cin >> u >> v >> c;
    --u, --v;
    g[u].push_back(make_pair(v, c));
    g[v].push_back(make_pair(u, c));
  }
  vector<int> ans(n, -1);
  while (true) {
    while (!now[0].empty()) {
      int q = now[0].top();
      now[0].pop();
      ans[ind[q]] = t;
      ++num;
    }
    if (num == n) break;
    dfs(0, -1);
    ++t;
  }
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
