#include <bits/stdc++.h>
using namespace std;
long long labs(long long a) { return a < 0 ? (-a) : a; }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
template <typename T>
struct Point {
  T x, y;
  Point() {}
  Point(T xx, T yy) : x(xx), y(yy) {}
};
template <typename T>
bool operator<(const Point<T> &p1, const Point<T> &p2) {
  return p1.x < p2.x || p1.x == p2.x && p1.y < p2.y;
}
const int MAXN = 5005;
struct Node {
  int priority;
  short divs[MAXN];
  int answer;
  vector<pair<int, int> > edges;
  Node() {}
};
vector<Node> g;
int cnts[MAXN];
int divs_map[MAXN];
int n;
void DFS(int i, int from, int trains) {
  for (int(j) = 0; (j) < (g[i].edges.size()); (j)++) {
    if (g[i].edges[j].first != from)
      DFS(g[i].edges[j].first, i, g[i].edges[j].second);
  }
  if (from == -1) return;
  int nt = 0;
  memset((cnts), 0, sizeof(cnts));
  for (int(j) = 0; (j) < (n); (j)++) {
    if (g[i].divs[j] < 0) continue;
    int now;
    for (now = g[i].divs[j]; cnts[now] >= trains; now++)
      ;
    cnts[now]++;
    g[from].divs[j] = now + 1;
  }
}
void Collapse() {
  map<int, int> tmp;
  for (int(i) = 0; (i) < (n); (i)++) {
    tmp[g[i].priority] = i;
  }
  int num = 0;
  for (map<int, int>::iterator it = tmp.begin(); it != tmp.end(); it++, num++) {
    g[it->second].priority = num;
    g[it->second].divs[num] = 0;
    divs_map[num] = it->second;
  }
}
int main() {
  cin >> n;
  g.resize(n);
  for (int(i) = 0; (i) < (n); (i)++) {
    cin >> g[i].priority;
    fill(g[i].divs, g[i].divs + MAXN, -1);
  }
  Collapse();
  int a, b, c;
  for (int(i) = 0; (i) < (n - 1); (i)++) {
    cin >> a >> b >> c;
    --a;
    --b;
    g[a].edges.push_back(make_pair(b, c));
    g[b].edges.push_back(make_pair(a, c));
  }
  DFS(0, -1, 0);
  for (int(i) = 0; (i) < (n); (i)++) {
    g[divs_map[i]].answer = g[0].divs[i];
  }
  for (int(i) = 0; (i) < (n); (i)++) {
    cout << g[i].answer << " ";
  }
  return 0;
}
