#include <bits/stdc++.h>
using namespace std;
int n, a[5555], p[5555], d[5555], c[5555];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
    Q[5555];
vector<pair<int, int>> adj[5555];
int t[5555];
void orient(int x, int prev = -1) {
  p[x] = prev;
  for (auto e : adj[x])
    if (e.first != prev) {
      d[e.first] = d[x] + 1;
      c[e.first] = e.second;
      orient(e.first, x);
    }
}
int main() {
  cin >> n;
  for (int i(0); i < n; ++i) {
    cin >> a[i];
    Q[i].push({a[i], i});
  }
  for (int i(1); i < n; ++i) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    --x, --y;
    adj[x].push_back(pair<int, int>(y, c));
    adj[y].push_back(pair<int, int>(x, c));
  }
  orient(0);
  vector<int> order(n - 1);
  iota((order).begin(), (order).end(), 1);
  sort((order).begin(), (order).end(),
       [](int x, int y) { return d[x] < d[y]; });
  for (int now = 1; int((Q[0]).size()) != n; ++now) {
    for (int x : order) {
      int y = p[x];
      for (int i(0); i < c[x]; ++i) {
        if (int((Q[x]).size()) == 0) break;
        auto v = Q[x].top();
        Q[x].pop();
        t[v.second] = now;
        Q[y].push(v);
      }
    }
  }
  for (int i(0); i < n; ++i) printf("%d ", t[i]);
  puts("");
  return 0;
}
