func_code_string: #include<bits/stdc++.h>      using namespace std;      #define FOR(i, j, k) for(int i = j; i <= k; i++)   #define ROF(i, j, k) for(int i = j; i >= k; i--)   #define PB push_back   #define MEM(n, val) memset((n), val, sizeof(n))   #define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);   #define F first   #define S second   #define MP make_pair   #define LL long long   #define MOD 1000000007   #define MX 200010   #define INFL 1000000000000000000LL   #define INF 1000000000      typedef pair<int, int> PII;   typedef pair<LL, LL> PLL;      int fx[] = {0, 0, 1, -1};   int fy[] = {1, -1, 0, 0};      int n, x;   vector<int> adjl[100010];   int mxlev;   int mxfreq;   int lev_freq[100010];   int freq[100010];   vector<PII> frv;   bool is_lev_a[100010];   int lev[100010];   vector<int> ultalv[100010];         void func(int u, int lv) {       mxlev = max(lv, mxlev);       lev_freq[lv]++;       lev[u] = lv;       ultalv[ lv ].PB(u);       for(int v: adjl[u]) {           func(v, lv + 1);       }   }      int dp[450][100001];   //PII bt[320][100001];      map<int, int> mp_cnt;      int main() {   //    freopen( in.txt ,  r , stdin);   //    freopen( out.txt ,  w , stdout);       FastIO;       mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());          cin >> n >> x;       FOR(v, 2, n) {           int u;           cin >> u;           adjl[u].PB(v);   //        cout << u <<   :   << v <<   n ;       }          func(1, 1);             FOR(i, 1, mxlev) {           freq[ lev_freq[i] ]++;           mxfreq = max(mxfreq, lev_freq[i]);       }       FOR(i, 1, mxfreq) {           if(freq[i]) {               frv.PB({i, freq[i]});           }       }      //    FOR(i, 1, mxlev) {   //        cout << i <<   :   << lev_freq[i] <<   n ;   //    }   //    cout <<   n ;   //    FOR(i, 1, mxfreq) {   //        cout << i <<   :   << freq[i] <<   n ;   //    }   //    cout <<   n ;   //    for(PII val: frv) {   //        cout << val.F <<   :   << val.S <<   n ;   //    }   //    if(x == 237) {   //        cout <<  sz :   << frv.size() << endl;   //    }       MEM(dp, -1);   //    MEM(bt, -1);       int turn = 0;       for(int i = 0; i < frv.size(); i++) {           int val = frv[i].F;           int fr = frv[i].S;           dp[i][0] = 0;           for(int j = 1; j <= x; j++) {               if(i != 0 && dp[i - 1][j] >= 0) {                   dp[i][ j ] = 0;   //                bt[i][j] = {i - 1, j};                   continue;               }               if((j - val >= 0) && (dp[i][j - val] >= 0) && (dp[i][j - val] < fr)) {                   dp[i][j] = dp[i][j - val] + 1;   //                bt[i][j] = {i, j - val};               }           }       }      //    cout <<  dp :  n ;   //    for(int i = 0; i < frv.size(); i++) {   //        for(int j = 0; j <= x; j++) {   //            cout << dp[i][j] <<    ;   //        }   //        cout <<   n ;   //    }   //    cout <<   n ;   //   //    cout << dp[ (int)frv.size() - 1 ][x] <<   n n ;          if(dp[ (int)frv.size() - 1 ][x] >= 0) {           int a = frv.size() - 1, b = x;           while(a != -1 && b != -1) {               if(dp[a][b]) {   //                cout << frv[a].F <<   :   << dp[a][b] <<   n ;                   mp_cnt[ frv[a].F ] = max(mp_cnt[ frv[a].F ], dp[a][b]);               }       //        cout << a <<     << b <<   :   << frv[a].F <<   :   << dp[a][b] <<   n ;               PII nn = {-1, -1};               if(a != 0 && dp[a][b] == 0 && dp[a - 1][b] >= 0) {                   nn = {a - 1, b};               }               int val = frv[a].F;               int fr = frv[a].S;               if((b - val >= 0) && (dp[a][b - val] >= 0) && (dp[a][b - val] < fr) && (dp[a][b] == dp[a][b - val] + 1)) {   //                dp[i][j] = dp[i][j - val] + 1;                   nn = {a, b - val};   //                bt[i][j] = {i, j - val};               }                  a = nn.F;               b = nn.S;           }              FOR(i, 1, mxlev) {               if(mp_cnt[ lev_freq[i] ]) {                   mp_cnt[ lev_freq[i] ]--;                   is_lev_a[i] = 1;               }           }              cout << mxlev <<   n ;           FOR(i, 1, n) {               if(is_lev_a[ lev[i] ]) {                   cout <<  a ;               }               else {                   cout <<  b ;               }           }           return 0;       }          map<int, int> exp;       int sum = n;       FOR(i, 1, mxlev) {           if(lev_freq[i] <= x) {               is_lev_a[i] = 1;               x -= lev_freq[i];               sum -= lev_freq[i];           }           else if(lev_freq[i] <= sum - x) {               sum -= lev_freq[i];           }           else {               vector<int> leaf, nonleaf;               for(int u: ultalv[i]) {                   if(adjl[u].size() > 0) {                       nonleaf.PB(u);                   }                   else {                       leaf.PB(u);                   }               }               if(x >= nonleaf.size()) {                   /// use all x                   sum -= x;                   for(int u: nonleaf) {                       exp[u] = 1;                   }                   x -= nonleaf.size();                   for(int j = 0; j < x; j++) {                       int u = leaf[j];                       exp[u] = 1;                   }                   sum -= leaf.size() - x;                   x = 0;               }               else {                   /// use all sum - x   //                sum = x;   //                x = lev_freq[i] - (sum - x);                   sum -= nonleaf.size();                   int leafbaki = (int)leaf.size() - (sum - x);                      for(int j = 0; j < leafbaki; j++) {                       int u = leaf[j];                       exp[u] = 1;                   }                   x -= leafbaki;                   sum = x;               }           }       }          cout << mxlev + 1 <<   n ;       FOR(i, 1, n) {           if(exp[i]) {               cout <<  a ;               continue;           }           if(is_lev_a[ lev[i] ]) {               cout <<  a ;           }           else {               cout <<  b ;           }       }       return 0;   }   /**   2000000000000   */   