#include <bits/stdc++.h>
using namespace std;
const long long MAXVAL = (long long)1e18 + 1;
const long long MOD = 1000000007ll;
const double INF = 1e9;
long long poww(int x, long long pow) {
  if (pow == 0ll) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x) % MOD;
  }
  return ans % MOD;
}
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}
struct pt {
  long long x, y;
};
long long dot(const pt& p1, const pt& p2) { return p1.x * p2.x + p1.y * p2.y; }
long long cross(const pt& p1, const pt& p2) {
  return p1.x * p2.y - p1.y * p2.x;
}
bool cmp_angles(const pt& p1, const pt& p2, const pt& p3, const pt& p4) {
  pt po1 = {dot(p1, p2), abs(cross(p1, p2))};
  pt po2 = {dot(p3, p4), abs(cross(p3, p4))};
  return cross(po1, po2) >= 0;
}
bool top(const pair<int, int>& p) {
  return p.second > 0 || (p.second == 0 && p.first < 0);
}
const int nmax = 5001;
vector<vector<pair<int, int>>> gr(nmax);
vector<int> pi(nmax, -1);
vector<int> prop(nmax, -1);
vector<set<pair<int, int>>> lists(nmax);
vector<int> alive;
vector<int> pr(nmax);
void bfs() {
  queue<int> vs;
  vs.push(0);
  while (!vs.empty()) {
    int v = vs.front();
    vs.pop();
    alive.push_back(v);
    for (auto& nextp : gr[v]) {
      int next = nextp.first;
      if (next == pi[v]) continue;
      int pp = nextp.second;
      pi[next] = v;
      prop[next] = pp;
      vs.push(next);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  while (q-- > 0) {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
      int x;
      cin >> x;
      pr[i] = x;
    }
    for (int i = 0; i < n - 1; ++i) {
      int u, v, x;
      cin >> v >> u >> x;
      --v;
      --u;
      gr[u].emplace_back(v, x);
      gr[v].emplace_back(u, x);
    }
    bfs();
    for (int i = 0; i < n; ++i) lists[i].insert({pr[i], i});
    pi[0] = -1;
    prop[0] = nmax;
    int cnt = n;
    vector<int> ans(n);
    int time = 0;
    while (cnt) {
      for (int x : alive) {
        if (lists[x].empty()) continue;
        int propusk = prop[x];
        for (int i = 0; i < propusk; ++i) {
          int next = (*lists[x].begin()).second;
          lists[x].erase(lists[x].begin());
          if (pi[x] >= 0)
            lists[pi[x]].insert({pr[next], next});
          else {
            --cnt;
            ans[next] = time;
          }
          if (lists[x].empty()) break;
        }
      }
      ++time;
    }
    for (int i = 0; i < n; ++i) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
