#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double eps = (1e-8);
int dcmp(long double x, long double y) {
  if (abs(x - y) <= eps)
    return 0;
  else if (x > y)
    return -1;
  return 1;
}
vector<pair<int, int> > adj[5005];
int nxt[5005], cap[5005];
void dfs(int cur, int p) {
  for (auto to : adj[cur]) {
    if (to.first != p) {
      nxt[to.first] = cur;
      cap[to.first] = to.second;
      dfs(to.first, cur);
    }
  }
}
int travelledFrom[5005], curPos[5005], ans[5005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int> > a;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.push_back({x, i});
    curPos[i] = i;
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    --x;
    --y;
    adj[x].push_back({y, c});
    adj[y].push_back({x, c});
  }
  dfs(0, -1);
  sort(a.begin(), a.end());
  for (bool play = 1; play;) {
    play = 0;
    memset(travelledFrom, 0, sizeof(travelledFrom));
    for (int i = 0; i < n; ++i) {
      int indx = a[i].second;
      if (curPos[indx] == 0) continue;
      play = 1;
      ans[indx]++;
      if (travelledFrom[curPos[indx]] < cap[curPos[indx]]) {
        travelledFrom[curPos[indx]]++;
        curPos[indx] = nxt[curPos[indx]];
      }
    }
  }
  for (int i = 0; i < n; ++i) cout << ans[i] << ' ';
  return 0;
}
