#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int t, c;
  Edge() {}
  Edge(int t, int c) : t(t), c(c) {}
};
int main() {
  int n;
  cin >> n;
  vector<vector<Edge> > g(n);
  vector<vector<pair<int, int> > > x(n);
  {
    for (int i = 0; i < (int)(n); i++) {
      int a;
      cin >> a;
      x[i].push_back(pair<int, int>(a, i));
    }
    for (int i = 0; i < (int)(n - 1); i++) {
      int u, v, c;
      cin >> u >> v >> c;
      u--;
      v--;
      g[u].push_back(Edge(v, c));
      g[v].push_back(Edge(u, c));
    }
  }
  vector<int> ans(n, -1);
  ans[0] = 0;
  for (int k = 0; k < (int)(n); k++) {
    for (int i = 0; i < (int)(x[0].size()); i++) ans[x[0][i].second] = k;
    x[0].clear();
    for (int i = 0; i < (int)(n); i++) sort((x[i]).rbegin(), (x[i]).rend());
    stack<int> st;
    st.push(0);
    vector<bool> used(n, false);
    used[0] = true;
    while (!st.empty()) {
      int cur = st.top();
      st.pop();
      for (int i = 0; i < (int)(g[cur].size()); i++) {
        int nxt = g[cur][i].t;
        int cap = g[cur][i].c;
        if (used[nxt]) continue;
        used[nxt] = true;
        int sz = min(cap, (int)x[nxt].size());
        for (int j = 0; j < (int)(sz); j++) {
          x[cur].push_back(x[nxt].back());
          x[nxt].pop_back();
        }
        st.push(nxt);
      }
    }
  }
  for (int i = 0; i < (int)(n); i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
