#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > adj;
int parent[5123];
int cap[5123];
void build(int node, int par, int cp) {
  parent[node] = par;
  cap[node] = cp;
  for (int i = 0; i < (int)adj[node].size(); i++)
    if (adj[node][i].first != par)
      build(adj[node][i].first, node, adj[node][i].second);
}
int peror[5123];
priority_queue<pair<int, int> > pq[5123];
int ans[5123];
vector<pair<int, int> > topush[5123];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &peror[i]);
    pq[i].push(make_pair(-peror[i], i));
  }
  adj.resize(n + 2);
  int u, v, c;
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &u, &v, &c);
    adj[u].push_back(make_pair(v, c));
    adj[v].push_back(make_pair(u, c));
  }
  build(1, 1, 1000);
  int cnt = n;
  int itnum = 0;
  while (cnt > 0) {
    while (pq[1].size()) {
      cnt--;
      ans[pq[1].top().second] = itnum;
      pq[1].pop();
    }
    for (int i = 2; i <= n; i++) {
      int cp = cap[i];
      int par = parent[i];
      while (pq[i].size() && cp) {
        cp--;
        topush[par].push_back(pq[i].top());
        pq[i].pop();
      }
    }
    for (int i = 1; i <= n; i++) {
      while (topush[i].size()) {
        pq[i].push(topush[i].back());
        topush[i].pop_back();
      }
    }
    itnum++;
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
}
