#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
template <class T>
T sqr(T x) {
  return x * x;
}
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
pair<int, int> p[5005];
vector<pair<int, int> > v[5005];
priority_queue<int, vector<int>, greater<int> > pq[5005];
map<int, int> m;
int ans[5005] = {0};
int day;
int ansct;
void dfs(int cur) {
  for (int i = 0; i < v[cur].size(); ++i) {
    if (v[cur][i].first == p[cur].first) continue;
    p[v[cur][i].first].first = cur;
    p[v[cur][i].first].second = v[cur][i].second;
    dfs(v[cur][i].first);
  }
}
void dfs2(int cur) {
  if (cur != 1) {
    int cnt = p[cur].second;
    while (cnt && !pq[cur].empty()) {
      pq[p[cur].first].push(pq[cur].top());
      pq[cur].pop();
      --cnt;
    }
  } else {
    while (!pq[cur].empty()) {
      ans[m[pq[cur].top()]] = day - 1;
      pq[cur].pop();
      --ansct;
    }
  }
  for (int i = 0; i < v[cur].size(); ++i) {
    if (v[cur][i].first == p[cur].first) continue;
    dfs2(v[cur][i].first);
  }
}
int main(int argc, char** argv) {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    pq[i].push(x);
    m[x] = i;
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    v[a].push_back(make_pair(b, c));
    v[b].push_back(make_pair(a, c));
  }
  dfs(1);
  ansct = n - 1;
  pq[1].pop();
  for (day = 1; ansct; ++day) {
    dfs2(1);
  }
  for (int i = 1; i <= n; ++i) printf("%d%c", ans[i], i == n ? '\n' : ' ');
  return (EXIT_SUCCESS);
}
