#include <bits/stdc++.h>
using namespace std;
vector<int> out[5050];
vector<int> cap[5050];
int have[5050][5050];
int parent[5050];
int up[5050];
void pre(int x, int p, int ccc) {
  parent[x] = p;
  up[x] = ccc;
  for (int i = 0; i < out[x].size(); ++i) {
    int &y = out[x][i];
    if (y != p) {
      pre(y, x, cap[x][i]);
    }
  }
}
int ans[5050];
void dfs(int x, int t, int ind) {
  if (x == 1) {
    ans[ind] = t;
    return;
  }
  while (have[x][t] + 1 > up[x]) {
    t++;
  }
  have[x][t]++;
  dfs(parent[x], t + 1, ind);
}
pair<int, int> arr[5050];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &arr[i].first);
    arr[i].second = i;
  }
  int u, v, w;
  for (int i = 1; i < n; ++i) {
    scanf("%d %d %d", &u, &v, &w);
    out[u].push_back(v);
    cap[u].push_back(w);
    out[v].push_back(u);
    cap[v].push_back(w);
  }
  pre(1, 0, 0);
  sort(arr + 1, arr + n + 1);
  for (int i = 1; i <= n; ++i) {
    dfs(arr[i].second, 1, arr[i].second);
  }
  for (int i = 1; i <= n; ++i) {
    if (i != 1) printf(" ");
    printf("%d", ans[i] - 1);
  }
  printf("\n");
  return 0;
}
