#include <bits/stdc++.h>
using namespace std;
struct div_ {
  int index;
  int pos;
  int prio;
};
bool compare(div_ d1, div_ d2) { return (d1.prio < d2.prio); }
int main() {
  int n;
  cin >> n;
  vector<div_> divs;
  for (int count = 0; count < n; count++) {
    int temp;
    div_ div1;
    cin >> temp;
    div1.index = count + 1;
    div1.pos = count + 1;
    div1.prio = temp;
    divs.push_back(div1);
  }
  vector<int> lines;
  lines.resize(n + 1, 0);
  vector<int> diss;
  diss.resize(n + 1, 0);
  vector<int> parents;
  parents.resize(n + 1, 0);
  parents[1] = 1;
  for (int count = 0; count < n - 1; count++) {
    int from, to, dis;
    cin >> from >> to >> dis;
    if (parents[to] != 0) {
      lines[from] = to;
      diss[from] = dis;
      parents[from] = to;
    } else if (parents[from] != 0) {
      lines[to] = from;
      diss[to] = dis;
      parents[to] = from;
    }
  }
  sort(divs.begin(), divs.end(), compare);
  int counta = 1, times = 0;
  vector<int> used;
  used.resize(n + 1);
  vector<int> answer;
  answer.resize(n + 1, 0);
  while (counta < n) {
    for (int count = 0; count < n + 1; count++) used[count] = 0;
    times++;
    for (int count = 0; count < n; count++) {
      if (used[divs[count].pos] < diss[divs[count].pos]) {
        used[divs[count].pos]++;
        divs[count].pos = parents[divs[count].pos];
        if (divs[count].pos == 1) {
          answer[divs[count].index] = times;
          counta++;
        }
      }
    }
  }
  for (int count = 0; count < n; count++) {
    cout << answer[count + 1] << " ";
  }
}
