#include <bits/stdc++.h>
using namespace std;
vector<int> adjList[5010];
vector<pair<int, int>> edges[5010];
int C[5010], P[5010];
vector<pair<int, int>> dfs(int u, int p) {
  vector<pair<int, int>> curr;
  curr.push_back(make_pair(0, P[u]));
  for (auto v : adjList[u])
    if (v != p) {
      auto ret = dfs(v, u);
      for (auto t : ret) curr.push_back(t);
    }
  sort(curr.begin(), curr.end());
  if (u == 0) return curr;
  vector<pair<int, int>> fin;
  priority_queue<int, vector<int>, greater<int>> q;
  int day = 0;
  auto it = curr.begin();
  while (true) {
    while (it != curr.end() && it->first <= day) {
      q.push(it->second);
      it++;
    }
    int total = 0;
    while (!q.empty() && total < C[u]) {
      int x = q.top();
      q.pop();
      fin.push_back(make_pair(day + 1, x));
      total += 1;
    }
    day += 1;
    if (it == curr.end() && q.empty()) break;
  }
  return fin;
}
void predfs(int u, int p) {
  for (auto x : edges[u])
    if (x.first != p) {
      C[x.first] = x.second;
      predfs(x.first, u);
    }
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> P[i];
  map<int, int> conv;
  for (int i = 0; i < N; i++) conv[P[i]] = i;
  for (int i = 0; i < N - 1; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    u--;
    v--;
    edges[u].push_back(make_pair(v, c));
    edges[v].push_back(make_pair(u, c));
    adjList[u].push_back(v);
    adjList[v].push_back(u);
  }
  predfs(0, -1);
  auto ret = dfs(0, -1);
  vector<int> ans(N);
  for (auto p : ret) ans[conv[p.second]] = p.first;
  for (auto x : ans) cout << x << " ";
  cout << endl;
}
