#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n;
int a[5000];
vector<pair<int, int> > g[5000];
int A[5000];
int par[5000];
int CAP[5000];
int cap[5000];
bool used[5000];
int place0[5000];
int place[5000];
int placeNext[5000];
int ret[5000];
void solution() {
  scanf("%d", &n);
  for (int i = 0, _n = (n); i < _n; ++i) {
    scanf("%d", a + i);
    A[i] = a[i];
  }
  sort(A, A + n);
  for (int i = 0, _n = (n); i < _n; ++i) {
    a[i] = lower_bound(A, A + n, a[i]) - A;
    place0[a[i]] = place[a[i]] = i;
  }
  for (int i = 0, _n = (n - 1); i < _n; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    g[a - 1].push_back(pair<int, int>(b - 1, c));
    g[b - 1].push_back(pair<int, int>(a - 1, c));
  }
  queue<int> q;
  q.push(0);
  used[0] = true;
  par[0] = -1;
  for (int i = 0; i < n; i++) {
    int v = q.front();
    q.pop();
    for (int j = 0, _n = ((int)((g[v]).size())); j < _n; ++j) {
      int c = g[v][j].second;
      int v2 = g[v][j].first;
      if (!used[v2]) {
        q.push(v2);
        par[v2] = v;
        used[v2] = true;
        CAP[v2] = c;
      }
    }
  }
  memset((ret), (-1), sizeof((ret)));
  for (int t = 0;; t++) {
    bool changed = 0;
    memcpy(cap, CAP, sizeof(cap));
    for (int i = 0, _n = (n); i < _n; ++i) {
      int p = place[i];
      if (place[i] == 0) {
        if (ret[place0[i]] == -1) ret[place0[i]] = t;
        continue;
      }
      if (cap[place[i]] == 0)
        placeNext[i] = p;
      else {
        placeNext[i] = par[p];
        cap[place[i]]--;
        changed = true;
      }
    }
    memcpy(place, placeNext, sizeof(place));
    if (!changed) break;
  }
  for (int i = 0; i < n; i++) printf("%d ", ret[i]);
  puts("");
}
int main() {
  solution();
  return 0;
}
