#include <bits/stdc++.h>
using namespace std;
struct division {
  int priority;
  int number;
};
bool operator<(division a, division b) { return a.priority > b.priority; }
int n;
division d[200000];
vector<int> g[200000];
vector<int> c[200000];
bool used[200000];
int ans[200000];
vector<int> order;
int p[200000];
int can[200000];
priority_queue<division> cur[200000];
void dfs(int v) {
  used[v] = 1;
  order.push_back(v);
  for (int i = 0; i < g[v].size(); i++) {
    int u = g[v][i];
    if (!used[u]) {
      p[u] = v;
      can[u] = c[v][i];
      dfs(u);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &d[i].priority);
    d[i].number = i;
    cur[i].push(d[i]);
  }
  for (int i = 0; i < n - 1; i++) {
    int v, u, w;
    scanf("%d%d%d", &v, &u, &w);
    v--;
    u--;
    g[v].push_back(u);
    g[u].push_back(v);
    c[v].push_back(w);
    c[u].push_back(w);
  }
  dfs(0);
  int rest = n - 1;
  int day = 1;
  while (cur[0].size() != n) {
    rest = 0;
    for (int u = 1; u < n; u++) {
      int i = order[u];
      for (int j = 0; j < can[i]; j++) {
        if (cur[i].empty()) break;
        division w = cur[i].top();
        cur[i].pop();
        if (p[i] == 0) ans[w.number] = day;
        cur[p[i]].push(w);
      }
      rest += cur[i].size();
    }
    day++;
  }
  for (int i = 0; i < n; i++) printf("%d ", ans[i]);
  printf("\n");
  return 0;
}
