#include <bits/stdc++.h>
using namespace std;
struct edge {
  int v, c;
};
struct sol {
  int time, pos, pri, id;
};
struct cmp {
  bool operator()(const sol &a, const sol &b) { return a.pri < b.pri; }
};
vector<edge> adj[5005];
int N;
int P[5005], T[5005], F[5005], TF[5005];
int FIN[5005];
bool vis[5005];
vector<sol> arrange;
queue<sol> qwe;
void dfs(int cv, int par, int flow) {
  if (vis[cv]) return;
  T[cv] = par;
  F[cv] = flow;
  vis[cv] = 1;
  for (int i = 0; i < adj[cv].size(); i++) {
    edge tmp = adj[cv][i];
    if (tmp.v == par) continue;
    dfs(tmp.v, cv, tmp.c);
  }
}
int main() {
  scanf("%d\n", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &P[i]);
  for (int i = 0; i < N - 1; i++) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    adj[u].push_back((edge){v, c}), adj[v].push_back((edge){u, v});
  }
  memset(vis, 0, sizeof(vis));
  dfs(1, -1, 0);
  for (int i = 1; i <= N; i++) arrange.push_back((sol){0, i, P[i], i});
  sort(arrange.begin(), arrange.end(), cmp());
  for (int i = 0; i < arrange.size(); i++) qwe.push(arrange[i]);
  for (int i = 1; i <= N; i++) TF[i] = F[i];
  for (int i = 0; i <= 5000; i++) {
    for (int j = 1; j <= N; j++) F[j] = TF[j];
    while (!qwe.empty()) {
      sol tmp = qwe.front();
      if (tmp.time == i + 1) break;
      qwe.pop();
      if (tmp.pos == 1) {
        FIN[tmp.id] = tmp.time;
        continue;
      }
      if (F[tmp.pos] > 0) {
        F[tmp.pos]--, tmp.pos = T[tmp.pos];
      }
      tmp.time += 1;
      qwe.push(tmp);
    }
    if (qwe.empty()) break;
  }
  for (int i = 1; i <= N; i++) printf("%d ", FIN[i]);
  return 0;
}
