func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int n;   int m;   vector<pair<int, int> > w[5000];   pair<int, int> v[5000];   int p[5000], u[5000], pc[5000], px[5000], res[5000];   int go(int x, int p) {     for (int i = 0; i < ((int)(w[x]).size()); i++) {       int y = w[x][i].first;       int z = w[x][i].second;       if (y != p) {         px[y] = x;         pc[y] = z;         go(y, x);       }     }     return 0;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &v[i].first);       v[i].second = i;     }     sort(v, v + n);     for (int i = 1; i < n; i++) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       a--;       b--;       w[a].push_back(make_pair(b, c));       w[b].push_back(make_pair(a, c));     }     go(0, 0);     for (int i = 0; i < n; i++) {       p[i] = i;       res[i] = -1;     }     int it = 0;     while (true) {       int ok = 1;       for (int i = 0; i < n; i++) u[i] = 0;       for (int i = 0; i < n; i++) {         int j = v[i].second;         if (p[j] > 0 && u[p[j]] < pc[p[j]]) {           ok = 0;           u[p[j]]++;           p[j] = px[p[j]];         } else if (p[j] == 0 && res[j] == -1)           res[j] = it;       }       if (ok) break;       it++;     }     for (int i = 0; i < n; i++) printf( %d  , res[i]);     printf(  n );     return 0;   }   