#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double eps = (1e-8);
int dcmp(long double x, long double y) {
  if (abs(x - y) <= eps)
    return 0;
  else if (x > y)
    return -1;
  return 1;
}
vector<pair<int, int> > adj[5005];
pair<int, int> parent[5005];
void dfs(int cur, int p) {
  for (auto to : adj[cur]) {
    if (to.first != p) {
      parent[to.first] = {cur, to.second};
      dfs(to.first, cur);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<priority_queue<int, vector<int>, greater<int> > > a(n);
  map<int, int> ind;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ind[x] = i;
    a[i].push(x);
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y, c;
    cin >> x >> y >> c;
    --x;
    --y;
    adj[x].push_back({y, c});
    adj[y].push_back({x, c});
  }
  memset(parent, -1, sizeof(parent));
  dfs(0, -1);
  vector<int> ans(n);
  int totalTime = 0;
  bool play = 1;
  while (play) {
    play = 0;
    vector<vector<int> > psh(5005);
    ++totalTime;
    for (int i = 1; i < n; ++i) {
      int cnt = 0;
      int to = parent[i].first, cap = parent[i].second;
      while (!a[i].empty() && cnt < cap) {
        int div = a[i].top();
        a[i].pop();
        if (to != 0) {
          psh[to].push_back(div);
        } else {
          ans[ind[div]] = totalTime;
        }
        ++cnt;
      }
    }
    for (int i = 1; i < n; ++i) {
      for (int j = 0; j < (int)(psh[i]).size(); ++j) a[i].push(psh[i][j]);
      if (!a[i].empty()) play = 1;
    }
  }
  for (int i = 0; i < n; ++i) cout << ans[i] << ' ';
  return 0;
}
