#include <bits/stdc++.h>
using namespace std;
int N, EdgeNum;
int P[5005], T[5005], Pa[5005], Capa[5005];
int Head[5005], Next[5005 * 2], Ending[5005 * 2], Cost[5005 * 2];
pair<int, int> S[5005];
int Use[5005][5005];
bool Known[5005];
inline void InsEdge(int U, int V, int C) {
  Next[++EdgeNum] = Head[U];
  Head[U] = EdgeNum;
  Ending[EdgeNum] = V;
  Cost[EdgeNum] = C;
}
void DFS(int Cur) {
  Known[Cur] = 1;
  for (int i = Head[Cur]; i; i = Next[i])
    if (!Known[Ending[i]]) {
      Pa[Ending[i]] = Cur;
      Capa[Ending[i]] = Cost[i];
      DFS(Ending[i]);
    }
}
inline void Go(int Cur) {
  int Now = 0;
  for (int i = Cur; i != 1; i = Pa[i], ++Now) {
    while (Use[i][Now] == Capa[i]) ++Now;
    ++Use[i][Now];
  }
  T[Cur] = Now;
}
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &P[i]);
  for (int i = 1; i < N; ++i) {
    int A, B, C;
    scanf("%d%d%d", &A, &B, &C);
    InsEdge(A, B, C);
    InsEdge(B, A, C);
  }
  DFS(1);
  for (int i = 1; i <= N; ++i) S[i] = make_pair(P[i], i);
  sort(S + 1, S + N + 1);
  for (int i = 1; i <= N; ++i) Go(S[i].second);
  for (int i = 1; i <= N; ++i) printf("%d%c", T[i], (i == N) ? '\n' : ' ');
  return 0;
}
