#include <bits/stdc++.h>
struct Node {
  int d;
  std::pair<int, int> parent;
  std::vector<std::pair<int, int> > next;
  std::vector<int> used;
  Node() : d(-1), parent(std::make_pair(-1, -1)), used(5000) {}
};
std::vector<Node> nodes;
void dfs(int p, int d) {
  nodes[p].d = d;
  for (std::vector<std::pair<int, int> >::iterator i = nodes[p].next.begin();
       i != nodes[p].next.end(); ++i) {
    int next = (*i).first;
    if (nodes[next].d == -1) {
      nodes[next].parent = std::make_pair(p, (*i).second);
      dfs(next, d + 1);
    }
  }
}
int main() {
  int n;
  std::cin >> n;
  nodes = std::vector<Node>(n + 1);
  std::vector<std::pair<int, int> > pri(n + 1);
  for (int i = 1; i <= n; ++i) {
    std::pair<int, int> p;
    std::cin >> p.first;
    p.second = i;
    pri[i] = p;
  }
  std::sort(pri.begin(), pri.end());
  for (int i = 1; i <= n - 1; ++i) {
    int v, u, c;
    std::cin >> v >> u >> c;
    nodes[v].next.push_back(std::make_pair(u, c));
    nodes[u].next.push_back(std::make_pair(v, c));
  }
  dfs(1, 0);
  std::vector<int> res(n + 1);
  for (int i = 1; i <= n; ++i) {
    int j = pri[i].second;
    int t = 0;
    while (1) {
      if (j == 1) {
        break;
      }
      int u = nodes[j].used[t];
      int c = nodes[j].parent.second;
      int next = nodes[j].parent.first;
      if (c - u > 0) {
        nodes[j].used[t] += 1;
        j = next;
      }
      ++t;
    }
    res[pri[i].second] = t;
  }
  for (int i = 1; i <= n; ++i) {
    std::cout << res[i];
    if (i != n) {
      std::cout << " ";
    }
  }
  std::cout << std::endl;
}
