#include <bits/stdc++.h>
using namespace std;
const int N = 5000;
int cap[N];
int used[N][2 * N + 10];
int parent[N];
vector<pair<int, int> > edge[N];
int main() {
  int n;
  cin >> n;
  vector<pair<int, int> > prio(n);
  for (int i = 0; i < (n); ++i) {
    int x;
    cin >> x;
    prio[i] = pair<int, int>(x, i);
  }
  sort((prio).begin(), (prio).end());
  for (int i = 0; i < (n - 1); ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    edge[a].push_back(pair<int, int>(b, c));
    edge[b].push_back(pair<int, int>(a, c));
  }
  vector<int> ans(n);
  queue<int> Q;
  Q.push(0);
  fill(parent, parent + n, -1);
  while (Q.size()) {
    int v = Q.front();
    Q.pop();
    for (int i = 0; i < (((int)(edge[v]).size())); ++i) {
      int u = edge[v][i].first;
      int d = edge[v][i].second;
      if (u == parent[v]) continue;
      parent[u] = v;
      cap[u] = d;
      Q.push(u);
    }
  }
  for (int i = 0; i < (n); ++i) {
    int v = prio[i].second;
    int t = 0;
    while (v) {
      while (used[v][t] == cap[v]) t++;
      used[v][t]++;
      t++;
      v = parent[v];
    }
    ans[prio[i].second] = t;
  }
  copy((ans).begin(), (ans).end(), ostream_iterator<int>(cout, " "));
  cout << endl;
  return 0;
}
