#include <bits/stdc++.h>
using namespace std;
const int mxn = 5007;
int prio[mxn];
struct edge {
  int to, cap;
  edge(int _t, int _c) {
    to = _t;
    cap = _c;
  }
};
struct cmp {
  bool operator()(const int a, const int b) { return prio[a] > prio[b]; }
};
vector<edge> adj[mxn];
int n;
int parent[mxn];
int cap[mxn];
int sol[mxn];
int timer[mxn];
priority_queue<int, vector<int>, cmp> q[mxn];
set<int> vis;
vector<pair<int, int> > z;
void dfs(int v, int par, int dep) {
  for (int i = 0; i < (int)adj[v].size(); i++) {
    int nv = adj[v][i].to;
    if (nv == par) continue;
    int ncap = adj[v][i].cap;
    parent[nv] = v;
    cap[nv] = ncap;
    dfs(nv, v, dep + 1);
  }
  vis.insert(v);
  q[v].push(v);
  z.push_back(make_pair(dep, v));
}
int main(int argc, char** argv) {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &prio[i]);
  for (int i = 1; i < n; i++) {
    int f, t, cap;
    scanf("%d", &f);
    scanf("%d", &t);
    scanf("%d", &cap);
    adj[f].push_back(edge(t, cap));
    adj[t].push_back(edge(f, cap));
  }
  dfs(1, 1, 0);
  vector<int> order;
  sort(z.begin(), z.end());
  for (int i = 0; i < z.size(); i++) order.push_back(z[i].second);
  while (true) {
    bool change = false;
    for (int qi = 1; qi < n; qi++) {
      int i = order[qi];
      if (q[i].size() == 0) continue;
      change = 1;
      int upCap = cap[i];
      while (upCap-- && q[i].size() > 0) {
        int v = q[i].top();
        q[i].pop();
        sol[v] = 1 + timer[i];
        q[parent[i]].push(v);
      }
      timer[i]++;
    }
    if (!change) break;
  }
  for (int i = 1; i <= n; i++) {
    printf("%d%c", sol[i], i == n ? '\n' : ' ');
  }
  return 0;
}
