#include <bits/stdc++.h>
using namespace std;
struct TreeNode {
  int parent;
  vector<int> children;
};
class TreeInitializer {
 public:
  TreeInitializer() { adjacency = new int[5000][5000]{}; }
  ~TreeInitializer() { delete[] adjacency; }
  inline void AddLink(int a, int b, int capacity) {
    adjacency[a][b] = capacity;
    adjacency[b][a] = capacity;
    if (a > max) max = a;
    if (b > max) max = b;
  }
  vector<TreeNode> GetTree(int root) const {
    vector<TreeNode> tree(max + 1);
    vector<bool> visited(max + 1, false);
    queue<int> queueing;
    tree[root].parent = root;
    queueing.push(root);
    while (queueing.size() != 0) {
      int curr = queueing.front();
      queueing.pop();
      if (visited[curr]) continue;
      visited[curr] = true;
      for (int i = 0; i <= max; ++i) {
        if (adjacency[curr][i] != 0 && !visited[i]) {
          tree[curr].children.push_back(i);
          tree[i].parent = curr;
          queueing.push(i);
        }
      }
    }
    return tree;
  }
  int GetCapacity(int a, int b) { return adjacency[a][b]; }

 private:
  int max = 0;
  int (*adjacency)[5000];
};
struct Link {
  int pointa;
  int pointb;
  int capacity;
};
struct Soldier {
  Soldier(int number, int priority)
      : SoliderNumber(number), priority(priority) {}
  int SoliderNumber;
  int priority;
  inline bool operator<(const Soldier& another) const {
    return priority > another.priority;
  }
};
struct Station {
  int next;
  int capacity;
  priority_queue<Soldier> watting;
};
class Solution {
 public:
  vector<int> Solve(const vector<int>& priorities, const vector<Link>& links) {
    vector<int> result(priorities.size());
    vector<int> moveOrder;
    vector<Station> stations = InitializeStations(priorities, links, moveOrder);
    int end = moveOrder.size() - 1;
    int movingCount = priorities.size();
    int day = 0;
    while (true) {
      while (stations[0].watting.size() != 0) {
        int number = stations[0].watting.top().SoliderNumber;
        stations[0].watting.pop();
        result[number] = day;
        --movingCount;
      }
      if (movingCount == 0) break;
      int finalStation = 1;
      for (int i = 0; i <= end; ++i) {
        Station& currentStation = stations[moveOrder[i]];
        Station& nextStation = stations[currentStation.next];
        int transferCount = 0;
        for (; transferCount < currentStation.capacity; ++transferCount) {
          if (currentStation.watting.size() == 0) break;
          const Soldier& movingSoldier = currentStation.watting.top();
          nextStation.watting.push(movingSoldier);
          currentStation.watting.pop();
        }
        if (transferCount != 0) finalStation = i;
      }
      end = finalStation;
      ++day;
    }
    return result;
  }

 private:
  vector<Station> InitializeStations(const vector<int>& priorities,
                                     const vector<Link>& links,
                                     vector<int>& moveOrder) {
    vector<Station> stations(priorities.size());
    for (int i = 0; i < priorities.size(); ++i) {
      stations[i].watting.emplace(i, priorities[i]);
    }
    TreeInitializer treeini;
    for (const Link& link : links)
      treeini.AddLink(link.pointa, link.pointb, link.capacity);
    auto nodes = treeini.GetTree(0);
    int begin = 0;
    moveOrder.clear();
    moveOrder.reserve(priorities.size());
    moveOrder.push_back(0);
    while (begin != moveOrder.size()) {
      int index = moveOrder[begin];
      TreeNode& current = nodes[index];
      ++begin;
      stations[index].next = current.parent;
      stations[index].capacity = treeini.GetCapacity(index, current.parent);
      for (int child : current.children) moveOrder.push_back(child);
    }
    return stations;
  }
};
int main() {
  Solution solution;
  int n;
  cin >> n;
  vector<int> prio(n);
  vector<Link> link;
  link.reserve(n - 1);
  for (int i = 0; i < n; ++i) cin >> prio[i];
  for (int i = 1; i < n; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    link.push_back({a, b, c});
  }
  vector<int> result = solution.Solve(prio, link);
  int final = result.back();
  result.pop_back();
  for (int time : result) cout << time << ' ';
  cout << final;
  return 0;
}
