#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = 4 * atan(1);
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int nCase = 0;
int dcmp(double x) {
  if (fabs(x) < eps) return 0;
  return x < 0 ? -1 : 1;
}
template <class T>
inline bool read(T& n) {
  T x = 0, tmp = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
  if (c == EOF) return false;
  if (c == '-') c = getchar(), tmp = -1;
  while (c >= '0' && c <= '9') x *= 10, x += (c - '0'), c = getchar();
  n = x * tmp;
  return true;
}
template <class T>
inline void write(T n) {
  if (n < 0) {
    putchar('-');
    n = -n;
  }
  int len = 0, data[20];
  while (n) {
    data[len++] = n % 10;
    n /= 10;
  }
  if (!len) data[len++] = 0;
  while (len--) putchar(data[len] + 48);
}
struct Statu {
  int id, val, t;
  bool operator<(const Statu& rhs) const { return val > rhs.val; }
};
int p[5010];
vector<Statu> vec[5010];
struct Edge {
  int v, c, nxt;
} e[5010 * 2];
int head[5010], ecnt;
int a[5010];
int n;
int o;
void dfs(int u, int f, int c) {
  if (~f) {
    sort(vec[u].begin(), vec[u].end());
    for (int i = 0; i < vec[u].size(); ++i) vec[u][i].t++;
    while (c && vec[u].size()) {
      c--;
      vec[f].push_back(vec[u].back());
      vec[u].pop_back();
    }
  }
  for (int i = head[u]; i != -1; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    dfs(v, u, e[i].c);
  }
}
int main(int argc, const char* argv[]) {
  cin >> n;
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  memset(head, -1, sizeof head), ecnt = 0;
  int u, v, c;
  for (int i = 1; i < n; ++i) {
    scanf("%d%d%d", &u, &v, &c);
    e[ecnt] = Edge{v, c, head[u]}, head[u] = ecnt++;
    e[ecnt] = Edge{u, c, head[v]}, head[v] = ecnt++;
  }
  for (int i = 1; i <= n; ++i) {
    vec[i].push_back(Statu{i, p[i], 0});
  }
  while (vec[1].size() != n) {
    o++;
    dfs(1, -1, INF);
  }
  for (int i = 0; i < n; ++i) {
    int id = vec[1][i].id;
    p[id] = vec[1][i].t;
  }
  for (int i = 1; i <= n; ++i) cout << p[i] << ' ';
  cout << endl;
  return 0;
}
