#include <bits/stdc++.h>
using namespace std;
int n, m, k;
bool debug = false;
int a[5005], fa[5005], c1[5005], cc[5005], ans[5005];
vector<pair<int, int>> mp[5005], q;
void dfs(int x, int f, int c) {
  fa[x] = f;
  c1[x] = c;
  for (auto p : mp[x])
    if (p.first != f) {
      dfs(p.first, x, p.second);
    }
}
int main() {
  scanf("%d", &n);
  int v, u, c;
  for (int i = 0; i < n; i++) {
    scanf("%d", &c);
    q.push_back({c, i});
  }
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &v, &u, &c);
    v--;
    u--;
    mp[v].push_back({u, c});
    mp[u].push_back({v, c});
  }
  sort(q.begin(), q.end());
  for (int i = 0; i < n; i++) q[i] = {q[i].second, q[i].second};
  dfs(0, -1, 0);
  for (int day = 0, cl = 1; cl < n; day++) {
    for (int i = 0; i < n; i++) cc[i] = c1[i];
    for (int i = 0; i < n; i++) {
      int pos = q[i].second;
      if (pos != 0 && cc[pos] && fa[pos] >= 0) {
        cc[pos]--;
        q[i].second = fa[pos];
        if (fa[pos] == 0) {
          cl++;
          ans[q[i].first] = day + 1;
        }
      }
    }
  }
  for (int i = 0; i < n; i++) printf("%d ", ans[i]);
  return 0;
}
