#include <bits/stdc++.h>
int IntMaxVal = (int)1e20;
long long LongMaxVal = (long long)1e20;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  ;
  vector<int> a(n);
  {
    for (int i = 0; i < n; i++) cin >> a[i];
  };
  vector<vector<int> > edges(n);
  vector<int> from;
  vector<int> to;
  vector<int> cap;
  for (int i = 0; i < n - 2 + 1; ++i) {
    int a;
    cin >> a;
    ;
    int b;
    cin >> b;
    ;
    int c;
    cin >> c;
    ;
    a--;
    b--;
    edges[a].push_back(i);
    edges[b].push_back(i);
    from.push_back(a);
    to.push_back(b);
    cap.push_back(c);
  }
  vector<int> order(1, 0);
  vector<int> parent(n);
  vector<int> capToTop(n);
  parent[0] = -1;
  for (int i = 0; i < n - 1 + 1; ++i) {
    int v = order[i];
    for (int ci = 0; ci < (int)edges[v].size() - 1 + 1; ++ci) {
      int edge = edges[v][ci];
      int other = from[edge] == v ? to[edge] : from[edge];
      if (parent[v] == other) continue;
      parent[other] = v;
      capToTop[other] = cap[edge];
      order.push_back(other);
    }
  }
  int arrived = 1;
  vector<int> res(n);
  res[0] = 0;
  vector<vector<pair<int, int> > > qs(n);
  for (int i = 1; i < n - 1 + 1; ++i) {
    qs[i].push_back(make_pair(-a[i], i));
  }
  int t = 0;
  while (arrived < n) {
    t++;
    for (int i = 1; i < n - 1 + 1; ++i) {
      int v = order[i];
      for (int j = 0; j < capToTop[v] - 1 + 1; ++j) {
        if (qs[v].size()) {
          pop_heap(qs[v].begin(), qs[v].end());
          auto traveller = qs[v].back();
          qs[v].pop_back();
          if (parent[v] == 0) {
            arrived++;
            res[traveller.second] = t;
          } else {
            qs[parent[v]].push_back(traveller);
            push_heap(qs[parent[v]].begin(), qs[parent[v]].end());
          }
        } else
          break;
      }
    }
  }
  for (int i = 0; i < n - 1 + 1; ++i) cout << res[i] << ' ';
}
