#include <bits/stdc++.h>
using namespace std;
struct tree {
  int to, cap;
  priority_queue<pair<int, pair<int, int> > > Pque;
};
vector<int> sequence;
vector<vector<int> > mp;
bool vis[5005];
vector<pair<int, pair<int, int> > > cp;
tree tr[5005];
void DFS(int idx, tree *tr, int prev = -1) {
  if (idx != 0) {
    tr[idx].to = prev;
  }
  vis[idx] = 1;
  sequence.push_back(idx);
  for (int i = 0; i < mp[idx].size(); i++) {
    if (!vis[mp[idx][i]]) {
      DFS(mp[idx][i], tr, idx);
    }
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int l;
    scanf("%d", &l);
    tr[i].Pque.push({-1 * l, {i, 0}});
  }
  tr[0].to = -1;
  tr[0].cap = 0;
  mp.resize(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int l, k, r;
    scanf("%d %d %d", &l, &k, &r);
    l--;
    k--;
    mp[l].push_back(k);
    mp[k].push_back(l);
    cp.push_back({r, {l, k}});
  }
  DFS(0, tr);
  for (int i = 0; i < n - 1; i++) {
    if (tr[cp[i].second.first].to == cp[i].second.second) {
      tr[cp[i].second.first].cap = cp[i].first;
    }
    if (tr[cp[i].second.second].to == cp[i].second.first) {
      tr[cp[i].second.second].cap = cp[i].first;
    }
  }
  int time[n];
  memset(time, 0, n);
  int k = 0;
  while (tr[0].Pque.size() < n && k < n) {
    k++;
    for (int i = 0; i < n; i++) {
      if (tr[sequence[i]].Pque.size() == 0) continue;
      if (sequence[i] == 0) continue;
      for (int j = 0; j < tr[sequence[i]].cap; j++) {
        if (tr[sequence[i]].Pque.size() == 0) break;
        if (tr[sequence[i]].to == 0)
          tr[tr[sequence[i]].to].Pque.push(
              {tr[sequence[i]].Pque.top().first,
               {tr[sequence[i]].Pque.top().second.first,
                tr[sequence[i]].Pque.top().second.second + k}});
        else
          tr[tr[sequence[i]].to].Pque.push(
              {tr[sequence[i]].Pque.top().first,
               {tr[sequence[i]].Pque.top().second.first,
                tr[sequence[i]].Pque.top().second.second}});
        tr[sequence[i]].Pque.pop();
      }
    }
  }
  while (tr[0].Pque.size() > 0) {
    time[tr[0].Pque.top().second.first] = tr[0].Pque.top().second.second;
    tr[0].Pque.pop();
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", time[i]);
  }
}
