#include <bits/stdc++.h>
using namespace std;
int City[5555];
vector<pair<int, int> > V;
int N;
int Time[5555];
int Prev[5555];
int Used[5555];
vector<int> G[5555];
vector<int> T[5555];
int C[5555];
int Left[5555];
void DFS(int u) {
  Used[u] = 1;
  for (int i = 0; i < (int)(G[u]).size(); ++i) {
    int v = G[u][i];
    if (!Used[v]) {
      Prev[v] = u;
      C[v] = T[u][i];
      DFS(v);
    }
  }
}
void Solve() {
  scanf("%d", &N);
  for (int i = 0; i < N; ++i) {
    City[i] = i + 1;
    int r;
    scanf("%d", &r);
    V.push_back(make_pair(r, i));
  }
  sort((V).begin(), (V).end());
  for (int i = 1; i < N; ++i) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    G[u].push_back(v);
    T[u].push_back(c);
    G[v].push_back(u);
    T[v].push_back(c);
  }
  DFS(1);
  C[1] = 100000;
  for (int t = 0; t < 5555; ++t) {
    for (int i = 1; i <= N; ++i) {
      Left[i] = C[i];
    }
    for (int k = 0; k < N; ++k) {
      int d = V[k].second;
      int city = City[d];
      if (city == 0) {
        continue;
      }
      if (city == 1) {
        Time[d] = t;
      }
      if (Left[city]) {
        Left[city]--;
        city = Prev[city];
        City[d] = city;
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    printf("%d ", Time[i]);
  }
}
int main() {
  Solve();
  return 0;
}
