#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<int>> p(n);
  vector<vector<int>> pi(n);
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]] = i;
    p[i].push_back(a[i]);
  }
  vector<vector<pair<int, int>>> s(n);
  for (int i = 0; i < n - 1; i++) {
    int v, u, c;
    cin >> v >> u >> c;
    s[v - 1].push_back(make_pair(u - 1, c));
    s[u - 1].push_back(make_pair(v - 1, c));
  }
  vector<pair<int, pair<int, int>>> r(n, make_pair(-1, make_pair(-1, -1)));
  queue<int> q;
  q.push(0);
  r[0].first = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < s[u].size(); i++)
      if (r[s[u][i].first].first == -1) {
        r[s[u][i].first] =
            make_pair(r[u].first + 1, make_pair(u, s[u][i].second));
        q.push(s[u][i].first);
      }
  }
  vector<int> t(n, 0);
  t[0] = 0;
  int time = 1;
  int u = n - 1;
  p[0].clear();
  while (u) {
    for (int i = 1; i < n; i++)
      if (p[i].size() != 0) {
        sort(p[i].begin(), p[i].end());
        for (int j = 0; j < p[i].size() && j < r[i].second.second; j++)
          pi[r[i].second.first].push_back(p[i][j]);
        int h = p[i].size();
        if (r[i].second.second < h) h = r[i].second.second;
        p[i].erase(p[i].begin(), p[i].begin() + h);
      }
    for (int i = 1; i < n; i++)
      if (pi[i].size() != 0) {
        for (int j = 0; j < pi[i].size(); j++) p[i].push_back(pi[i][j]);
        pi[i].clear();
      }
    if (pi[0].size() != 0) {
      u -= pi[0].size();
      for (int j = 0; j < pi[0].size(); j++) t[m[pi[0][j]]] = time;
      pi[0].clear();
      time++;
    }
  }
  for (int i = 0; i < n; i++) cout << t[i] << " ";
}
