#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 3;
vector<pair<int, pair<int, int>>> s[N];
int n, p[N], c[N], ans[N], par[N], u, v, C, ch[N], mp[N];
queue<int> q;
vector<pair<int, int>> adj[N];
void DFS(int node, int pr = 0, int capacity = 0) {
  c[node] = capacity;
  par[node] = pr;
  for (int i = 0; i < adj[node].size(); ++i)
    if (adj[node][i].first != pr)
      ++ch[node], DFS(adj[node][i].first, node, adj[node][i].second);
  if (!ch[node]) q.push(node);
  s[node].push_back({p[node], {node, 0}});
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%d", p + i);
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d%d%d", &u, &v, &C);
    adj[u].push_back({v, C});
    adj[v].push_back({u, C});
  }
  DFS(1);
  int node, day;
  pair<int, pair<int, int>> x;
  while (q.front() != 1) {
    u = q.front();
    q.pop();
    ch[par[u]]--;
    if (!ch[par[u]]) q.push(par[u]);
    sort(s[u].begin(), s[u].end());
    for (int i = 0; i < s[u].size(); ++i) {
      x = s[u][i];
      node = x.second.first;
      day = x.second.second;
      while (mp[day] == c[u]) ++day;
      mp[day]++;
      ans[node] = day + 1;
      s[par[u]].push_back({p[node], {node, ans[node]}});
    }
    for (int i = 0; i < s[u].size(); ++i) {
      x = s[u][i];
      node = x.second.first;
      mp[ans[node] - 1]--;
    }
    s[u].clear();
  }
  for (int i = 1; i <= n; ++i) printf("%d ", ans[i]);
}
