#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > g[6000];
int t[6000], p[6000], d[6000];
pair<int, int> a[6000];
void dfs(int v) {
  for (int i = 0; i < int((int)(g[v]).size()); i++) {
    int u = g[v][i].first;
    if (u == p[v] || p[u] != -1) continue;
    p[u] = v;
    d[u] = g[v][i].second;
    dfs(u);
  }
}
int used[5000][6000], up[5000][6000];
int main() {
  cin >> n;
  for (int i = 0; i < int(n); i++) {
    scanf("%d", &a[i].first);
    a[i].second = i;
  }
  sort(a, a + n);
  for (int i = 0; i < int(n - 1); i++) {
    int x, y, c;
    scanf("%d%d%d", &x, &y, &c);
    x--, y--;
    g[x].push_back(pair<int, int>(y, c));
    g[y].push_back(pair<int, int>(x, c));
  }
  memset(p, -1, sizeof p);
  p[0] = 0;
  d[0] = 0;
  dfs(0);
  memset(t, 0, sizeof t);
  memset(used, 0, sizeof used);
  for (int i = 0; i < int(n); i++)
    for (int j = 0; j < int(6000); j++) up[i][j] = j;
  for (int i = 0; i < int(n); i++) {
    int u = a[i].second;
    int cur = 0;
    while (u != 0) {
      if (used[u][cur] < d[u]) {
        used[u][cur]++;
        while (used[u][up[u][cur]] == d[u]) up[u][cur]++;
      } else {
        while (used[u][cur] == d[u]) {
          cur = up[u][cur];
        }
        used[u][cur]++;
        while (used[u][up[u][cur]] == d[u]) up[u][cur]++;
      }
      cur++;
      u = p[u];
    }
    t[a[i].second] = cur;
  }
  for (int i = 0; i < int(n); i++) {
    cout << t[i];
    if (i != n - 1) cout << " ";
  }
  return 0;
}
