#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
  return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int(i) = 0; (i) < (t.size()); ++(i)) s << t[i] << " ";
  return s;
}
int a[5005], ojc[5005], divpos[5005], traincap[5005], maxcap[5005], wyn[5005];
vector<pair<int, int> > ve;
vector<pair<int, int> > adj[5005];
int main() {
  int(n);
  scanf("%d", &(n));
  for (int(i) = 1; (i) <= (n); ++(i)) scanf("%d", a + i);
  for (int(i) = 1; (i) <= (n); ++(i)) ve.push_back(make_pair(a[i], i));
  sort(ve.begin(), ve.end());
  for (int(i) = 0; (i) < (n - 1); ++(i)) {
    int(v), (u), (c);
    scanf("%d %d %d", &(v), &(u), &(c));
    adj[v].push_back(make_pair(u, c));
    adj[u].push_back(make_pair(v, c));
  }
  deque<pair<int, int> > q;
  q.push_back(make_pair(1, -1));
  while (!q.empty()) {
    int v = q.front().first, skad = q.front().second;
    q.pop_front();
    ojc[v] = skad;
    for (typeof(adj[v].begin()) it = adj[v].begin(); it != adj[v].end(); it++) {
      if (it->first != skad) q.push_back(make_pair(it->first, v));
    }
  }
  for (int(i) = 1; (i) <= (n); ++(i)) {
    for (typeof(adj[i].begin()) it = adj[i].begin(); it != adj[i].end(); it++) {
      if (it->first == ojc[i]) maxcap[i] = it->second;
    }
  }
  wyn[1] = 0;
  for (int(i) = (2); (i) <= (n); ++i) wyn[i] = 2147483647;
  for (int(i) = 1; (i) <= (n); ++(i)) divpos[i] = i;
  int turn = 0;
  while (1) {
    for (int(i) = 1; (i) <= (n); ++(i)) traincap[i] = 0;
    int arr = 0;
    for (int(i) = 0; (i) < (n); ++(i)) {
      int div = ve[i].second, city = divpos[div];
      if (city == 1) {
        (wyn[div]) = min((wyn[div]), (turn));
        arr++;
        continue;
      }
      if (traincap[city] != maxcap[city]) {
        traincap[city]++;
        divpos[div] = ojc[city];
      }
    }
    if (arr == n) break;
    ++turn;
  }
  for (int(i) = 1; (i) <= (n); ++(i)) printf("%d ", wyn[i]);
}
