#include <bits/stdc++.h>
using namespace std;
int pr[5010];
struct edge {
  int v, u, c;
};
edge E[5010 * 2];
vector<pair<int, int> > g[5010];
int color[5010], ans[5010];
void dfs(int v) {
  if (color[v]) return;
  color[v] = 1;
  for (typeof((g[v]).begin()) it = (g[v]).begin(); it != (g[v]).end(); it++) {
    dfs(it->first);
    if (E[it->second].v != v) swap(E[it->second].v, E[it->second].u);
  }
}
class cmp {
 public:
  inline bool operator()(int x, int y) { return pr[x] > pr[y]; }
};
priority_queue<int, vector<int>, cmp> Set[5010][2];
int main() {
  int n;
  cin >> n;
  for (int i = (int)(1); i <= (int)(n); i++) cin >> pr[i];
  for (int i = (int)(1); i <= (int)(n); i++) Set[i][0].push(i);
  for (int i = 0; i < (int)(n - 1); i++) {
    cin >> E[i].v >> E[i].u >> E[i].c;
    g[E[i].v].push_back(make_pair(E[i].u, i));
    g[E[i].u].push_back(make_pair(E[i].v, i));
  }
  dfs(1);
  for (int i = (int)(1); i <= (int)(n); i++) color[i] = 1;
  bool run = 1;
  while (run) {
    run = 0;
    for (int i = (int)(2); i <= (int)(n); i++) ans[i] += color[i];
    for (int i = 0; i < (int)(n - 1); i++) {
      int u = E[i].u, v = E[i].v, c = E[i].c;
      while (!Set[u][0].empty() && c) {
        run = 1;
        if (v == 1) color[Set[u][0].top()] = 0;
        Set[v][1].push(Set[u][0].top());
        Set[u][0].pop();
        --c;
      }
    }
    for (int i = (int)(1); i <= (int)(n); i++)
      while (!Set[i][1].empty()) {
        Set[i][0].push(Set[i][1].top());
        Set[i][1].pop();
      }
  }
  for (int i = (int)(1); i <= (int)(n); i++) cout << ans[i] << ' ';
  return 0;
}
