#include <bits/stdc++.h>
using namespace std;
int n;
long long arr[5005], parent[5005], ans[5005];
long long dist[5005][5005];
vector<int> v[5005], order;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq[5005];
void dfs(int cur, int prev) {
  parent[cur] = prev;
  order.push_back(cur);
  for (int i = 0; i < (int)v[cur].size(); i++) {
    int node = v[cur][i];
    if (node == prev) continue;
    dfs(node, cur);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v1, cap;
    cin >> u >> v1 >> cap;
    v[u].push_back(v1);
    v[v1].push_back(u);
    dist[u][v1] = cap;
    dist[v1][u] = cap;
  }
  dfs(1, 0);
  ans[1] = 0;
  for (int i = 1; i <= n; i++) pq[i].push(make_pair(arr[i], i));
  int cnt = 1;
  while (true) {
    if (pq[1].size() == n) break;
    for (int i = 1; i < order.size(); i++) {
      int node = order[i];
      int cap = dist[node][parent[node]];
      while (cap > 0 && pq[node].size()) {
        pair<int, int> temp = pq[node].top();
        int connode = temp.second;
        pq[node].pop();
        pq[parent[node]].push(temp);
        ans[connode] = cnt;
        cap--;
      }
    }
    cnt++;
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
