func_code_string: #include <bits/stdc++.h>   using namespace std;   int p[2005], c[2005];   int n, root = -1;   vector<int> v[2005];   int d[2005], vis[2005];   int ans[2005];   struct cmp {     bool operator()(int x, int y) { return d[x] > d[y]; }   };   priority_queue<int, vector<int>, cmp> q;   void dfs(int x) {     if (c[x] == 0) q.push(x);     for (auto y : v[x]) {       if (vis[y]) continue;       vis[y] = 1;       d[y] = d[x] + 1;       dfs(y);     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> p[i] >> c[i];       if (!p[i]) {         root = i;         continue;       }       v[i].push_back(p[i]);       v[p[i]].push_back(i);     }     vis[root] = 1;     dfs(root);     bool flag = true;     int count = 1;     while (!q.empty()) {       int _top = q.top();       q.pop();       ans[_top] = count++;       int head = p[_top];       while (head) {         c[head]--;         if (c[head] == 0) q.push(head);         head = p[head];       }     }     for (int i = 1; i <= n; i++) {       if (c[i] > 0) {         flag = false;         break;       }     }     if (flag) {       cout <<  YES  << endl;       for (int i = 1; i <= n; i++) cout << ans[i] <<    ;       cout << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }   