#include <bits/stdc++.h>
using namespace std;
struct s {
  int b, c;
};
s temp;
int ans[5003], val[5003], par[5003], lim[5003], arr[5003], step[5003];
bool vis[5003];
class cmp {
 public:
  bool operator()(const int& a, const int& b) { return val[a] >= val[b]; }
};
vector<s> v[5003];
priority_queue<int, vector<int>, cmp> pq[5003];
bool cmp1(int a, int b) { return step[a] < step[b]; }
int main() {
  int n, i, a, pre, sz, j, c1, c2, day, b;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &val[i]);
  for (i = 0; i < n - 1; i++) {
    scanf("%d%d%d", &a, &b, &temp.c);
    temp.b = b;
    v[a].push_back(temp);
    a ^= b ^= a ^= b;
    temp.b = b;
    v[a].push_back(temp);
  }
  queue<int> q;
  q.push(1);
  vis[1] = 1;
  step[1] = 0;
  while (!q.empty()) {
    pre = q.front();
    q.pop();
    sz = v[pre].size();
    for (i = 0; i < sz; i++) {
      j = v[pre][i].b;
      if (!vis[j]) {
        vis[j] = 1;
        q.push(j);
        par[j] = pre;
        lim[j] = v[pre][i].c;
        step[j] = step[pre] + 1;
      }
    }
  }
  for (i = 1; i <= n; i++) arr[i] = i;
  for (i = 2; i <= n; i++) pq[i].push(i);
  c1 = 0;
  day = 0;
  sort(arr + 1, arr + n + 1, cmp1);
  while (c1 < n - 1) {
    day++;
    for (i = 2; i <= n; i++) {
      j = arr[i];
      c2 = 0;
      while (c2 < lim[j] && !pq[j].empty()) {
        pre = pq[j].top();
        pq[j].pop();
        pq[par[j]].push(pre);
        c2++;
        if (par[j] == 1) {
          c1++;
          ans[pre] = day;
        }
      }
    }
  }
  for (i = 1; i < n; i++) printf("%d ", ans[i]);
  printf("%d\n", ans[i]);
  return 0;
}
