func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   long double PI = 4 * atan(1);   int n, r, val[2001], x, flag, ch[2001];   bool isChild[2001][2001];   pair<int, int> p[2001];   vector<int> v[2001];   queue<int> q1, q2, ans;   void solve(int i) {     int rem = ch[i] - p[i].second;     while (ans.size()) {       x = ans.front();       if (isChild[i][x]) {         if (rem > 0) {           val[x]++;           q2.push(x);         } else {           if (rem == 0) {             q2.push(i);             val[i] = val[x] + 1;           }           q2.push(x);         }         rem--;       } else {         q1.push(x);       }       ans.pop();     }     if (rem == 0 || !q2.size()) {       q2.push(i);       val[i] = 1;     }     while (q1.size() && q2.size()) {       if (val[q1.front()] >= val[q2.front()]) {         ans.push(q1.front());         q1.pop();       } else {         ans.push(q2.front());         q2.pop();       }     }     while (q1.size()) {       ans.push(q1.front());       q1.pop();     }     while (q2.size()) {       ans.push(q2.front());       q2.pop();     }   }   void dfs(int i, int p) {     for (int a : v[i]) {       if (a != p) {         dfs(a, i);       }     }     solve(i);     return;   }   void calc(int par, int i, int p) {     ch[par]++;     isChild[par][i] = true;     for (int a : v[i]) {       if (a != p) {         calc(par, a, i);       }     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 1; i < n + 1; i++) {       cin >> p[i].first >> p[i].second;       if (p[i].first != 0)         v[p[i].first].push_back(i);       else         r = i;     }     for (int i = 1; i < n + 1; i++) calc(i, i, p[i].first), ch[i]--;     for (int i = 1; i < n + 1; i++) {       if (p[i].second > ch[i]) {         cout <<  NO ;         return 0;       }     }     dfs(r, 0);     cout <<  YES n ;     for (int i = 1; i < n + 1; i++) cout << val[i] <<    ;     return 0;   }   