func_code_string: #include <bits/stdc++.h>   using namespace std;   struct node {     int k, a;     bool operator<(const node &X) const { return a > X.a; }   };   int n, fa[5010], limi[5010], ans[5010];   int order[5010], co;   vector<int> edge[5010];   vector<int> val[5010];   priority_queue<node> train[5010];   void dfs(int u, int father, int weight) {     order[++co] = u;     fa[u] = father;     limi[u] = weight;     for (int i = 0; i < edge[u].size(); i++) {       int v = edge[u][i];       int w = val[u][i];       if (v == father) continue;       dfs(v, u, w);     }   }   int main() {     cin >> n;     node tt;     for (int i = 1; i <= n; i++) {       cin >> tt.a;       tt.k = i;       train[i].push(tt);     }     int x, y, z;     for (int i = 1; i <= n - 1; i++) {       cin >> x >> y >> z;       edge[x].push_back(y);       val[x].push_back(z);       edge[y].push_back(x);       val[y].push_back(z);     }     co = 0;     dfs(1, 0, 0);     int cnt = 0;     for (int i = 0; i <= n - 1; i++) {       while (!train[1].empty()) {         tt = train[1].top();         train[1].pop();         ans[tt.k] = i;         cnt += 1;       }       if (cnt == n) break;       for (int i = 2; i <= n; i++) {         int u = order[i];         int v = fa[u];         int w = limi[u];         for (int i = 1; i <= w; i++) {           if (train[u].empty()) break;           tt = train[u].top();           train[u].pop();           train[v].push(tt);         }       }     }     for (int i = 1; i <= n; i++) cout << ans[i] <<    ;     cout << endl;     return 0;   }   