#include <bits/stdc++.h>
using namespace std;
int n;
struct chel {
  int nom;
  int val;
};
chel a[5003];
chel tem[5003];
void mergesort(chel *a, chel *b, int n) {
  int i, i0, i1, iRight, iEnd, width, j;
  for (width = 1; width < n; width *= 2)
    for (i = 0; i < n; i += width * 2) {
      i0 = i;
      i1 = iRight = min(i + width, n);
      iEnd = min(i + width * 2, n);
      for (j = i; i0 < iRight; j++)
        if (i1 == iEnd || a[i0].val < a[i1].val)
          b[j] = a[i0++];
        else
          b[j] = a[i1++];
      for (j = i; j < i1; j++) a[j] = b[j];
    }
}
struct rebro {
  int flow;
  int v;
};
vector<rebro> g[5003];
int ite;
int ans[5003];
int sity[5003][10003];
int last[5003];
void dfs(int x, int p) {
  int i, j;
  for (i = 0; i < g[x].size(); i++) {
    int coun = 0;
    if (g[x][i].v != p) {
      while (last[g[x][i].v] > 1 && coun < g[x][i].flow) {
        coun++;
        j = last[x];
        last[x]++;
        int val = sity[g[x][i].v][1];
        if (x == 0) ans[a[val].nom] = ite;
        while (sity[x][j >> 1] > val) {
          sity[x][j] = sity[x][j >> 1];
          j >>= 1;
        }
        sity[x][j] = val;
        last[g[x][i].v]--;
        val = sity[g[x][i].v][last[g[x][i].v]];
        sity[g[x][i].v][last[g[x][i].v]] = 1000000000;
        j = 1;
        while (val > sity[g[x][i].v][j * 2] ||
               val > sity[g[x][i].v][j * 2 + 1]) {
          if (sity[g[x][i].v][j * 2] < sity[g[x][i].v][j * 2 + 1]) {
            sity[g[x][i].v][j] = sity[g[x][i].v][j * 2];
            j *= 2;
          } else {
            sity[g[x][i].v][j] = sity[g[x][i].v][j * 2 + 1];
            j *= 2;
            j++;
          }
        }
        sity[g[x][i].v][j] = val;
      }
      dfs(g[x][i].v, x);
    }
  }
}
int main() {
  scanf("%d", &n);
  int i, j;
  for (i = 0; i < n; i++) {
    a[i].nom = i;
    scanf("%d", &a[i].val);
  }
  mergesort(a, tem, n);
  for (i = 0; i < n; i++) {
    for (j = 1; j < 10002; j++) sity[a[i].nom][j] = 1000000000;
    sity[a[i].nom][0] = -1000000000;
    last[a[i].nom] = 2;
    sity[a[i].nom][1] = i;
  }
  int x, y, z;
  for (i = 0; i < n - 1; i++) {
    scanf("%d %d %d", &x, &y, &z);
    x--;
    y--;
    rebro tem2;
    tem2.v = y;
    tem2.flow = z;
    g[x].push_back(tem2);
    tem2.v = x;
    g[y].push_back(tem2);
  }
  for (ite = 1; ite < n; ite++) dfs(0, 0);
  printf("%d", ans[0]);
  for (i = 1; i < n; i++) printf(" %d", ans[i]);
  printf("\n");
  return 0;
}
