#include <bits/stdc++.h>
using namespace std;
int const maxn = 5000 + 10;
int n, mark[maxn], bus[maxn], cast[maxn], par[maxn], day[maxn], location[maxn];
vector<pair<int, int> > way[maxn];
pair<int, int> sol[maxn];
void dfs(int u) {
  mark[u] = 1;
  for (int i = 0; i < way[u].size(); i++) {
    if (mark[way[u][i].first] == 0) {
      par[way[u][i].first] = u;
      dfs(way[u][i].first);
    }
  }
}
void how() {
  for (int i = 1; i < n + 1; i++)
    for (int j = 0; j < way[i].size(); j++) {
      if (i == par[way[i][j].first])
        cast[way[i][j].first] = way[i][j].second;
      else
        cast[i] = way[i][j].second;
    }
}
int main() {
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    int x;
    cin >> x;
    sol[i] = make_pair(x, i);
    location[i] = i;
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    way[u].push_back(make_pair(v, c));
    way[v].push_back(make_pair(u, c));
  }
  dfs(1);
  how();
  sort(sol + 1, sol + n + 1);
  for (int d = 1; d < 2 * n + 1; d++) {
    fill(bus + 1, bus + n + 1, 0);
    for (int s = 1; s < n + 1; s++) {
      if (day[sol[s].second] < d && location[sol[s].second] != 1 &&
          bus[location[sol[s].second]] < cast[location[sol[s].second]]) {
        bus[location[sol[s].second]]++;
        location[sol[s].second] = par[location[sol[s].second]];
        day[sol[s].second]++;
      }
      if (day[sol[s].second] < d && location[sol[s].second] != 1 &&
          bus[location[sol[s].second]] >= cast[location[sol[s].second]]) {
        day[sol[s].second]++;
      }
      if (location[sol[s].second] == 1) continue;
    }
  }
  for (int i = 1; i < n + 1; i++) {
    cout << day[i] << " ";
  }
}
