#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
template <class T>
inline T lcm(T a, T b) {
  a = abs(a);
  b = abs(b);
  return (a / gcd(a, b)) * b;
}
template <class T, class X>
inline bool getbit(T a, X i) {
  T t = 1;
  return ((a & (t << i)) > 0);
}
template <class T, class X>
inline T setbit(T a, X i) {
  T t = 1;
  return (a | (t << i));
}
template <class T, class X>
inline T resetbit(T a, X i) {
  T t = 1;
  return (a & (~(t << i)));
}
inline long long power(long long a, long long b) {
  long long multiply = 1;
  for (int i = (0); i < (b); i++) {
    multiply *= a;
  }
  return multiply;
}
int n;
vector<int> Graph[5005], Order;
int Parent[5005], Ans[5005], Priority[5005], Node[5005];
int x, y, z, Edges[5005][5005];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    all[5005];
void dfs(int u, int p) {
  Parent[u] = p;
  Order.push_back(u);
  for (int j = (0); j < ((int)Graph[u].size()); j++) {
    int v = Graph[u][j];
    if (p != v) dfs(v, u);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = (1); i < (n + 1); i++) scanf("%d", &Priority[i]);
  for (int i = (0); i < (n - 1); i++) {
    scanf("%d%d%d", &x, &y, &z);
    Graph[x].push_back(y);
    Graph[y].push_back(x);
    Edges[x][y] = z;
    Edges[y][x] = z;
  }
  dfs(1, 0);
  for (int i = (1); i < (n + 1); i++) {
    Node[i] = i;
    all[i].push(make_pair(Priority[i], i));
  }
  int cnt = 0;
  while (true) {
    bool flag = false;
    for (int i = (2); i < (n + 1); i++) {
      if (Node[i] != 1) Ans[i]++;
    }
    if (all[1].size() == n) break;
    for (int j = (1); j < (n); j++) {
      int i = Order[j];
      if (all[i].size() == 0) continue;
      flag = true;
      int cap = Edges[i][Parent[i]];
      while (cap > 0 && all[i].size()) {
        pair<int, int> P = all[i].top();
        cap--;
        all[i].pop();
        all[Parent[i]].push(P);
        int p = Parent[i];
        Node[P.second] = p;
      }
    }
  }
  for (int i = (1); i < (n + 1); i++) printf("%d ", Ans[i]);
  printf("\n");
  return 0;
}
