#include <bits/stdc++.h>
using namespace std;
struct tt {
  int id;
  int rank;
  int pos;
};
bool cmp_rank(const tt& a, const tt& b) { return a.rank < b.rank; }
int n;
tt ar[5000];
vector<pair<int, int> > con[5000];
int par[5000];
int cap[5000];
int filled[5000];
void gen_tree(int x, int p) {
  int i, a;
  for (i = 0; i < con[x].size(); i++) {
    a = con[x][i].first;
    if (a == p) continue;
    cap[a] = con[x][i].second;
    par[a] = x;
    gen_tree(a, x);
  }
}
int ans[5000];
int main() {
  scanf("%d", &n);
  int i;
  for (i = 0; i < n; i++) {
    ar[i].id = i;
    ar[i].pos = i;
    scanf("%d", &ar[i].rank);
  }
  int a, b, c;
  for (i = 0; i < n - 1; i++) {
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    con[a].push_back(pair<int, int>(b, c));
    con[b].push_back(pair<int, int>(a, c));
  }
  par[0] = -1;
  gen_tree(0, -1);
  sort(ar, ar + n, cmp_rank);
  ans[0] = 0;
  int it;
  for (it = 1;; it++) {
    bool done = true;
    memset(filled, 0, sizeof(filled));
    for (i = 0; i < n; i++) {
      int cpos = ar[i].pos;
      if (cpos == 0) continue;
      if (filled[cpos] == cap[cpos]) continue;
      done = false;
      filled[cpos]++;
      ar[i].pos = par[ar[i].pos];
      ans[ar[i].id] = it;
    }
    if (done) break;
  }
  for (i = 0; i < n; i++) {
    if (i) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
}
