#include <bits/stdc++.h>
using namespace std;
const int maxn = 5001;
vector<int> adj[maxn];
int par[maxn], zarfiat[maxn], tmp[maxn], ans[maxn], shahr[maxn], n;
pair<pair<int, int>, int> yal[maxn - 1];
pair<int, int> olaviat[maxn];
bool mark[maxn];
void dfs(int x) {
  mark[x] = 1;
  for (int i = 0; i < adj[x].size(); i++)
    if (!mark[adj[x][i]]) {
      par[adj[x][i]] = x;
      dfs(adj[x][i]);
    }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> olaviat[i].first;
    olaviat[i].second = i;
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> yal[i].first.first >> yal[i].first.second >> yal[i].second;
    adj[yal[i].first.first].push_back(yal[i].first.second);
    adj[yal[i].first.second].push_back(yal[i].first.first);
  }
  dfs(1);
  for (int i = 0; i < n - 1; i++) {
    if (par[yal[i].first.first] == yal[i].first.second)
      zarfiat[yal[i].first.first] = yal[i].second;
    else
      zarfiat[yal[i].first.second] = yal[i].second;
  }
  sort(olaviat + 1, olaviat + n + 1);
  for (int i = 1; i <= n; i++) shahr[i] = olaviat[i].second;
  for (int k = 0; k < n; k++) {
    for (int j = 1; j <= n; j++) tmp[j] = zarfiat[j];
    for (int i = 1; i <= n; i++)
      if (olaviat[i].second != 1) {
        ans[shahr[i]]++;
        if (tmp[olaviat[i].second] > 0) {
          tmp[olaviat[i].second]--;
          olaviat[i].second = par[olaviat[i].second];
        }
      }
  }
  for (int i = 1; i <= n; i++) cout << ans[i] << " ";
  return 0;
}
