#include <bits/stdc++.h>
using namespace std;
class sp {
 public:
  int q, e;
  sp *w;
  sp(int q1, sp *w1, int e1) {
    q = q1;
    w = w1;
    e = e1;
  }
};
sp *a[5000];
int s[5000], s1[5000], g[5000], *d[5000];
void qs(int q, int w) {
  int e = q, r = w, t = s[q + (rand() % (w - q + 1))], y;
  do {
    while (s[e] < t) e++;
    while (s[r] > t) r--;
    if (e <= r) {
      y = s[e];
      s[e] = s[r];
      s[r] = y;
      y = s1[e];
      s1[e] = s1[r];
      s1[r] = y;
      e++;
      r--;
    }
  } while (e <= r);
  if (q < r) qs(q, r);
  if (e < w) qs(e, w);
}
void l1(int q, int w, int t) {
  g[q] = t;
  sp *c;
  for (c = a[q]; c; c = c->w)
    if (c->q != w) l1(c->q, q, t + 1);
}
int l(int q) {
  sp *c;
  int r, t = 0;
  while (q) {
    for (c = a[q]; c; c = c->w)
      if (g[c->q] < g[q]) break;
    r = c->e;
    for (; !d[r][t]; t++)
      ;
    d[r][t]--;
    q = c->q;
    t++;
  }
  return t;
}
int main() {
  int q, w, e, r, t, h[5000];
  cin >> q;
  for (w = 0; w < q; w++) {
    cin >> s[w];
    s1[w] = w;
    a[w] = 0;
  }
  qs(0, q - 1);
  for (w = 1; w < q; w++) {
    cin >> e >> r >> t;
    e--;
    r--;
    a[e] = new sp(r, a[e], w);
    a[r] = new sp(e, a[r], w);
    d[w] = new int[q];
    for (e = 0; e < q; e++) d[w][e] = t;
  }
  l1(0, 0, 0);
  for (w = 0; w < q; w++) h[s1[w]] = l(s1[w]);
  for (w = 0; w < q; w++) cout << h[w] << " ";
  return 0;
}
