func_code_string: #include <bits/stdc++.h>   const long long mod = 1000 * 1000 * 1000 + 7;   const long long mod1 = 998244353;   const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;   using namespace std;   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = (long long)(res * x);       y = y >> 1;       x = (long long)(x * x);     }     return res;   }   bool vis[3000];   vector<long long> a[3000];   vector<pair<long long, long long> > fin[3000];   map<long long, long long> suc;   long long val[3000];   long long c[3000];   long long cur = 1;   bool dfs(long long parent) {     long long f = 0;     long long s = 0;     for (auto edge : a[parent]) {       f += 1;       if (!vis[edge]) {         vis[edge] = true;         bool x = dfs(edge);         if (x == false) return false;         s += int((fin[edge]).size());         for (int j = 0; j < int((fin[edge]).size()); j++)           fin[parent].push_back(fin[edge][j]);       }     }     if (f == 1 and parent != a[0][0]) {       if (c[parent] > s) return false;       while (suc[cur] != 0) cur += 1;       fin[parent].push_back({cur, parent});       val[parent] = cur;       suc[cur] = 1;     } else {       if (c[parent] > s)         return false;       else {         sort(fin[parent].begin(), fin[parent].end());         if (c[parent] == 0) {           val[parent] = fin[parent][0].first;           suc[val[parent]] = 1;           for (int j = 0; j < int((fin[parent]).size()); j++) {             fin[parent][j].first += 1;             val[fin[parent][j].second] += 1;           }           suc[fin[parent].back().first] = 1;           fin[parent].push_back({val[parent], parent});         } else if (c[parent] == s) {           val[parent] = fin[parent].back().first + 1;           suc[val[parent]] = 1;           fin[parent].push_back({val[parent], parent});         } else {           val[parent] = fin[parent][c[parent]].first;           suc[val[parent]] = 1;           for (int j = c[parent]; j < int((fin[parent]).size()); j++) {             fin[parent][j].first += 1;             val[fin[parent][j].second] += 1;           }           suc[fin[parent].back().first] = 1;           fin[parent].push_back({val[parent], parent});         }       }     }     return true;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (int(i) = (0); (i) < (n); ++(i)) {       long long x, y;       cin >> x >> y;       if (x != 0) a[i + 1].push_back(x);       a[x].push_back(i + 1);       c[i + 1] = y;     }     if (n == 1) {       if (c[1] == 0) {         cout <<  YES               <<   n ;         cout << 1;         return 0;       }     }     vis[a[0][0]] = true;     bool ans = dfs(a[0][0]);     if (ans == false) {       cout <<  NO ;     } else {       cout <<  YES             <<   n ;       for (int i = 1; i <= n; i++) cout << val[i] <<    ;     }     return 0;   }   