func_code_string: #include <bits/stdc++.h>   using namespace std;   const int dr[] = {0, -1, 0, 1, -1, 1, 1, -1};   const int dc[] = {1, 0, -1, 0, 1, 1, -1, -1};   const double eps = 1e-9;   template <class T>   void print(const vector<T> &v) {     ostringstream os;     for (int i = 0; i < (int)v.size(); ++i) {       if (i) os <<    ;       os << v[i];     }     cout << os.str() << endl;   }   template <class T>   int sz(const T &c) {     return (int)c.size();   }   template <class T>   void srt(T &c) {     sort(c.begin(), c.end());   }   template <class T>   void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   void checkmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   T sqr(T x) {     return x * x;   }   template <class T, class U>   T cast(U x) {     ostringstream os;     os << x;     T res;     istringstream is(os.str());     is >> res;     return res;   }   template <class T>   vector<T> split(string s, string x =    ) {     vector<T> res;     for (int i = 0; i < s.size(); i++) {       string a;       while (i < (int)s.size() && x.find(s[i]) == string::npos) a += s[i++];       if (!a.empty()) res.push_back(cast<T>(a));     }     return res;   }   template <class T>   bool inside(T r, T c, T R, T C) {     return r >= 0 && r < R && c >= 0 && c < C;   }   struct item {     int prio;     int pos;     bool operator<(const item &o) const { return prio > o.prio; }   };   void dfs(vector<vector<pair<int, int> > > &g, int u, int p,            vector<priority_queue<item> > &h) {     for (int i(0), _b(sz(g[u]) - 1); i <= _b; ++i) {       int v = g[u][i].first;       if (v == p) continue;       int c = g[u][i].second;       while (c > 0 && !h[v].empty()) {         h[u].push(h[v].top());         h[v].pop();         --c;       }       dfs(g, v, u, h);     }   }   int main(int argc, char *argv[]) {     int n;     cin >> n;     vector<priority_queue<item> > h(n);     vector<int> a(n);     for (int i(0), _n(n); i < _n; ++i) {       cin >> a[i];       item e = {a[i], i};       h[i].push(e);     }     vector<vector<pair<int, int> > > g(n);     for (int i(0), _n(n - 1); i < _n; ++i) {       int u, v, c;       cin >> u >> v >> c;       --u;       --v;       g[u].push_back(make_pair(v, c));       g[v].push_back(make_pair(u, c));     }     vector<int> res(n);     int t = 0;     int cnt = 0;     while (1) {       while (!h[0].empty()) {         item e = h[0].top();         h[0].pop();         res[e.pos] = t;         ++cnt;         if (cnt == n) goto m1;       }       dfs(g, 0, -1, h);       ++t;     }   m1:     print(res);     return 0;   }   