#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5100;
int d[MAXN][MAXN], w[MAXN], par[MAXN], ans[MAXN];
pair<int, int> a[MAXN];
vector<pair<int, int> > g[MAXN];
bool mark[MAXN];
void dfs(int v) {
  mark[v] = true;
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i].first, t = g[v][i].second;
    if (mark[u] == false) {
      dfs(u);
      par[u] = v;
      w[u] = t;
    }
  }
}
int calc(int v, int t) {
  if (v == 1) return t;
  if (d[v][t] < w[v]) {
    d[v][t]++;
    return calc(par[v], t + 1);
  }
  return calc(v, t + 1);
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  for (int i = 1; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  sort(a + 1, a + 1 + n);
  dfs(1);
  for (int i = 1; i <= n; i++) ans[a[i].second] = calc(a[i].second, 0);
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
