#include <bits/stdc++.h>
using namespace std;
int b[5001][5001];
int d[2][5001];
int m[5001];
int n;
void poisk(int v) {
  for (int i = 1; i <= n; i++) {
    if (!m[i] && i != v && b[v][i] > 0) {
      m[i] = 1;
      d[0][i] = v;
      d[1][i] = b[v][i];
      poisk(i);
    }
  }
}
int main() {
  scanf("%d", &n);
  int a[2][5001];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[1][i]);
    a[0][i] = i;
  }
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++)
      if (a[1][i] > a[1][j]) {
        swap(a[0][i], a[0][j]);
        swap(a[1][i], a[1][j]);
      }
  }
  int c, v, u;
  for (int i = 1; i < n; i++) {
    scanf("%d%d%d", &v, &u, &c);
    b[u][v] = c;
    b[v][u] = c;
  }
  poisk(1);
  int s = 0;
  int k = n - 1;
  int t[2][5001];
  for (int i = 1; i <= n; i++) {
    t[0][i] = i;
    t[1][i] = 0;
  }
  while (k > 0) {
    for (int i = 1; i <= n; i++) b[i][d[0][i]] = d[1][i];
    for (int i = 1; i <= n; i++) {
      if (t[0][a[0][i]] != 1) {
        if (b[t[0][a[0][i]]][d[0][t[0][a[0][i]]]] > 0) {
          b[t[0][a[0][i]]][d[0][t[0][a[0][i]]]]--;
          if (d[0][t[0][a[0][i]]] == 1) k--;
          t[0][a[0][i]] = d[0][t[0][a[0][i]]];
        }
        t[1][a[0][i]]++;
      }
    }
  }
  for (int i = 1; i <= n; i++) printf("%d ", t[1][i]);
  return 0;
}
