#include <bits/stdc++.h>
using namespace std;
struct T {
  int node;
  vector<int> nodes;
} graph[5001];
int pr[5001], out[5001];
bool vis[5001];
vector<pair<int, int> > tmp[5001], adj[5001];
void transform(int node) {
  vis[node] = 1;
  for (int i = 0; i < (int)tmp[node].size(); ++i) {
    if (!vis[tmp[node][i].first]) {
      adj[node].push_back(tmp[node][i]);
      graph[tmp[node][i].first].node = tmp[node][i].first;
      graph[tmp[node][i].first].nodes.push_back(tmp[node][i].first);
      transform(tmp[node][i].first);
    }
  }
  return;
}
bool cmp(const int &a, const int &b) { return (pr[a] < pr[b]); }
void dfs(int node) {
  int nxtNode, cap;
  for (int i = 0; i < (int)adj[node].size(); ++i) {
    nxtNode = adj[node][i].first;
    cap = adj[node][i].second;
    for (int j = 0; j < cap && graph[nxtNode].nodes.size(); ++j) {
      graph[node].nodes.push_back(graph[nxtNode].nodes[0]);
      graph[nxtNode].nodes.erase(graph[nxtNode].nodes.begin());
    }
    sort(graph[node].nodes.begin(), graph[node].nodes.end(), cmp);
    dfs(nxtNode);
  }
  return;
}
int main() {
  int n, a, b, c;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &pr[i + 1]);
  }
  for (int i = 1; i < n; ++i) {
    scanf("%d %d %d", &a, &b, &c);
    tmp[a].push_back(make_pair(b, c));
    tmp[b].push_back(make_pair(a, c));
  }
  transform(1);
  out[1] = 0;
  c = 1;
  for (int lvl = 1; c < n && lvl <= n; ++lvl) {
    dfs(1);
    for (int i = 0; i < (int)graph[1].nodes.size(); ++i) {
      out[graph[1].nodes[i]] = lvl;
      c++;
    }
    graph[1].nodes.clear();
  }
  for (int i = 1; i <= n; ++i) {
    if (i - 1) cout << " ";
    cout << out[i];
  }
  cout << endl;
  return 0;
}
