#include <bits/stdc++.h>
using namespace std;
int N, A[5555], P[5555], Fa[5555], Cap[5555], Now[5555];
int Ret[5555], Left[5555];
vector<int> E[5555], L[5555];
inline void BuildTree(int u) {
  for (int i = 0; i < E[u].size(); i++)
    if (E[u][i] != Fa[u]) {
      int v = E[u][i];
      Fa[v] = u;
      Cap[v] = L[u][i];
      BuildTree(v);
    }
}
inline bool Check() {
  for (int i = 1; i <= N; i++)
    if (Now[i] != 1) return false;
  return true;
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
    P[i] = Now[i] = i;
  }
  for (int i = 1, u, v, w; i < N; i++) {
    cin >> u >> v >> w;
    E[u].push_back(v);
    L[u].push_back(w);
    E[v].push_back(u);
    L[v].push_back(w);
  }
  BuildTree(1);
  for (int i = 1; i <= N; i++)
    for (int j = i + 1; j <= N; j++)
      if (A[i] > A[j]) {
        swap(A[i], A[j]);
        swap(P[i], P[j]);
      }
  for (; !Check();) {
    memcpy(Left, Cap, sizeof(Cap));
    for (int i = 1; i <= N; i++)
      if (Now[P[i]] != 1) {
        Ret[P[i]]++;
        if (Left[Now[P[i]]]) {
          Left[Now[P[i]]]--;
          Now[P[i]] = Fa[Now[P[i]]];
        }
      }
  }
  for (int i = 1; i < N; i++) cout << Ret[i] << " ";
  cout << Ret[N] << endl;
  return 0;
}
