#include <bits/stdc++.h>
const int INF = (1 << 31) - 1;
const double EPS = 1E-9;
const double PI = acos(-1);
using namespace std;
vector<bool> U;
vector<vector<int> > G;
vector<int> P, order, T;
int M[5100][5100];
void dfs(int v) {
  U[v] = true;
  for (int i = 0; i < G[v].size(); ++i)
    if (!U[G[v][i]]) {
      P[G[v][i]] = v;
      dfs(G[v][i]);
    }
  order.push_back(v);
}
int main() {
  int n, a, b, c;
  cin >> n;
  priority_queue<pair<int, int> > Q[n];
  G.resize(n);
  P.resize(n);
  T.resize(n);
  T.assign(n, 0);
  U.resize(n);
  U.assign(n, false);
  for (int i = 0; i < n; ++i) {
    cin >> a;
    Q[i].push(make_pair(-a, i));
  }
  for (int i = 0; i < n - 1; ++i) {
    cin >> a >> b >> c;
    G[a - 1].push_back(b - 1);
    G[b - 1].push_back(a - 1);
    M[a - 1][b - 1] = c;
    M[b - 1][a - 1] = c;
  }
  P[0] = -1;
  dfs(0);
  int TIMER = 0;
  reverse(order.begin(), order.end());
  while (Q[0].size() < n) {
    TIMER++;
    for (int i = 1; i < n; ++i)
      for (int j = 0; j < M[order[i]][P[order[i]]] && !Q[order[i]].empty();
           ++j) {
        pair<int, int> v = Q[order[i]].top();
        Q[order[i]].pop();
        Q[P[order[i]]].push(v);
        if (P[order[i]] == 0) T[v.second] = TIMER;
      }
  }
  for (int i = 0; i < n; ++i) cout << T[i] << " ";
  cout << endl;
  return 0;
}
