#include <bits/stdc++.h>
using namespace std;
int res[8192];
vector<int> e[8192];
int p[8192], con[8192], pos[8192], c2[8192], inv[8192];
map<pair<int, int>, int> c;
vector<pair<int, int> > vp;
vector<int> q[2];
int n;
void dfs(int t, int f) {
  p[t] = f;
  for (int i = 0; i < (e[t].size()); i++)
    if (e[t][i] != f) {
      dfs(e[t][i], t);
    }
}
int main() {
  memset(res, -1, sizeof res);
  cin >> n;
  for (int i = 0; i < (n); i++) {
    int t;
    cin >> t;
    vp.push_back(make_pair(t, i));
  }
  sort(vp.begin(), vp.end());
  int cur = 0, old = 1;
  for (int i = 0; i < (n); i++) {
    q[cur].push_back(i);
    pos[i] = vp[i].second;
    inv[i] = pos[i];
  }
  for (int i = 0; i < (n - 1); i++) {
    int a, b, cc;
    cin >> a >> b >> cc;
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
    c[make_pair(a, b)] = cc;
    c[make_pair(b, a)] = cc;
  }
  dfs(0, -1);
  for (int i = 0; i < (n); i++)
    if (p[i] >= 0) {
      c2[i] = c[make_pair(i, p[i])];
    }
  int tm = 0;
  while (q[cur].size()) {
    swap(cur, old);
    q[cur].clear();
    memset(con, 0, sizeof con);
    for (int i = 0; i < (q[old].size()); i++) {
      int now = q[old][i], pnow = pos[now];
      if (pos[now] == 0) {
        res[inv[now]] = tm;
      } else {
        q[cur].push_back(now);
        if (con[pnow] >= c2[pnow]) {
        } else {
          pos[now] = p[pos[now]];
          con[pnow]++;
        }
      }
    }
    tm++;
  }
  for (int i = 0; i < (n); i++) printf("%d%c", res[i], i == n - 1 ? '\n' : ' ');
  return 0;
}
