#include <bits/stdc++.h>
using namespace std;
int N;
int as[1 << 20];
vector<int> conn[1 << 20];
vector<int> cost[1 << 20];
int par[1 << 20];
int pc[1 << 20];
pair<int, int> prior[1 << 20];
void pdfs(int n, int f) {
  for (size_t i = 0; i < conn[n].size(); ++i) {
    int t = conn[n][i];
    if (t == f) continue;
    par[t] = n;
    pc[t] = cost[n][i];
    pdfs(t, n);
  }
}
int block[5002][2 * 5002];
int res[1 << 20];
int main() {
  cin >> N;
  for (int i = 0; i < N; ++i)
    cin >> as[i], prior[i] = pair<int, int>(as[i], i + 1);
  for (int i = 0; i < N - 1; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    conn[a].push_back(b);
    conn[b].push_back(a);
    cost[a].push_back(c);
    cost[b].push_back(c);
  }
  pdfs(1, -1);
  sort(prior, prior + N);
  for (int i = 0; i < N; ++i) {
    int k = prior[i].second;
    int t = 0;
    int c = k;
    while (c > 1) {
      while (block[c][t] >= pc[c]) ++t;
      ++block[c][t++];
      c = par[c];
    }
    res[k] = t;
  }
  for (int i = 1; i < N; ++i) cout << res[i] << ' ';
  cout << res[N] << '\n';
}
