#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
vector<pair<int, int> > edge[5050];
priority_queue<int, vector<int>, greater<int> > city[5050];
int RES[5050];
int n, a, b, c;
int day;
void dfs(int pos, int parent, int cap) {
  int cnt = 0;
  while (((long long)city[pos].size()) && cnt++ != cap) {
    if (parent != 0)
      city[parent].push(city[pos].top());
    else
      RES[mp[city[pos].top()]] = day;
    city[pos].pop();
  }
  for (long long i = 0; i < ((long long)((long long)edge[pos].size())); i++)
    if (edge[pos][i].first != parent) {
      dfs(edge[pos][i].first, pos, edge[pos][i].second);
    }
}
int main() {
  scanf("%d", &n);
  for (long long i = 0; i < ((long long)n); i++) {
    scanf("%d", &a);
    city[i + 1].push(a);
    mp[a] = i + 1;
  }
  for (long long i = 0; i < ((long long)n - 1); i++) {
    scanf("%d%d%d", &a, &b, &c);
    edge[b].push_back(make_pair(a, c));
    edge[a].push_back(make_pair(b, c));
  }
  day = 0;
  for (long long i = 0; i < ((long long)n); i++) {
    dfs(1, 0, n);
    day++;
  }
  for (long long i = 0; i < ((long long)n); i++) printf("%d ", RES[i + 1]);
  printf("\n");
}
