#include <bits/stdc++.h>
using namespace std;
int a[5000], p[5000], pred[5000], cnt[5000][5005], ans[5000];
bool cmp(int x, int y) { return a[x] < a[y]; }
vector<vector<pair<int, int> > > g;
void dfs(int v, int pp, int cost) {
  pred[v] = pp;
  if (pp != -1)
    for (int i = 0; i < 5005; i++) cnt[v][i] = cost;
  for (size_t i = 0; i < g[v].size(); i++)
    if (g[v][i].first != pp) dfs(g[v][i].first, v, g[v][i].second);
}
int main() {
  int n;
  cin >> n;
  g.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    p[i] = i;
  }
  sort(p + 1, p + n, cmp);
  int x, y, z;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &x, &y, &z);
    --x;
    --y;
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  dfs(0, -1, 0);
  for (int i = 0; i < n; i++) {
    int r = p[i];
    int days = 0;
    while (r != 0) {
      for (int i = days; i < 5005; i++)
        if (cnt[r][i] > 0) {
          cnt[r][i]--;
          r = pred[r];
          days = i + 1;
          break;
        }
    }
    ans[p[i]] = days;
  }
  for (int i = 0; i < n; i++) printf("%d ", ans[i]);
  return 0;
}
