#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long INFll = 1000000000000000000ll;
const long double EPS = 1e-5;
const int MOD = 1000000007;
vector<pair<int, int> > g[5500];
pair<int, int> a[5500];
int pos[5500], ans[5500], pr[5500], b[5500], c[5500];
void dfs(int v, int p) {
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i].first, z = g[v][i].second;
    if (to != p) {
      pr[to] = v;
      b[to] = z;
      dfs(to, v);
    }
  }
}
int main() {
  ios_base::sync_with_stdio();
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
    pos[i] = i;
  }
  for (int i = 1; i <= n - 1; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    g[x].push_back(make_pair(y, z));
    g[y].push_back(make_pair(x, z));
  }
  ans[1] = -1;
  sort(a + 1, a + 1 + n);
  dfs(1, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= n; j++) c[j] = 0;
    for (int j = 1; j <= n; j++) {
      int x = a[j].second;
      if (pos[x] == 1) continue;
      if (c[pos[x]] < b[pos[x]]) {
        c[pos[x]]++;
        pos[x] = pr[pos[x]];
      }
      if (pos[x] == 1) ans[x] = i;
    }
  }
  for (int i = 1; i <= n; i++) cout << ans[i] + 1 << endl;
  return 0;
}
