#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define mp make_pair
#define fr first
#define sc second

int lg(ll n) {
    assert(n > 0);
    int ans = -1;
    while (n) {
        ans++;
        n >>= 1;
    }
    return ans;
}

void solve() {
    int n, x;
    cin >> n >> x;
    pair<int, char> a = mp(x, 'a'), b = mp(n - x, 'b');
    if (a > b) {
        assert(x > n - x);
        swap(a, b);
        x = n - x;
    }
    vector<vector<int>> adj(n);
    for (int i = 1; i < n; i++) {
        int p;
        cin >> p;
        p--;
        adj[p].push_back(i);
    }
    vector<int> dep(n), sz(n);
    dep[0] = 0;
    function<void(int)> dfs = [&](int cur) {
        sz[cur] = 1;
        for (int nxt : adj[cur]) {
            dep[nxt] = dep[cur] + 1;
            dfs(nxt);
            sz[cur] += sz[nxt];
        }
    };
    dfs(0);
    int depmax = *max_element(dep.begin(), dep.end());

    vector<pair<int, vector<int>>> depcnt_idx(depmax + 1);
    for (int i = 0; i < n; i++) {
        depcnt_idx[dep[i]].fr++;
        depcnt_idx[dep[i]].sc.push_back(i);
    }
    sort(depcnt_idx.begin(), depcnt_idx.end());

    vector<pair<int, vector<vector<int>>>> depcnt_values;
    for (auto [cnt, vec] : depcnt_idx) {
        assert(cnt != 0);
        assert(cnt == (int)vec.size());
        if (depcnt_values.empty() || depcnt_values.back().fr != cnt) {
            depcnt_values.emplace_back(cnt, vector<vector<int>>{});
        }
        depcnt_values.back().sc.push_back(vec);
    }
    /*for (auto [cnt, vvec] : depcnt_values) {
        cout << cnt << '\n';
        for (auto vec : vvec) {
            for (auto idx : vec) cout << idx << ' ';
            cout << '\n';
        }
        cout << '\n';
    }*/

    vector<int> freq(depcnt_values.size());
    for (int i = 0; i < (int)freq.size(); i++) {
        freq[i] = depcnt_values[i].sc.size();
    }

    vector<vector<int>> dp(x + 1, vector<int>(freq.size() + 1)),
        parent(n, vector<int>(freq.size() + 1));
    ;
    dp[0][0] = 1;
    for (int j = 0; j < (int)freq.size(); j++) {
        int val = depcnt_values[j].fr;
        int fre = freq[j];
        // cout << val << ' ' << fre << '\n';
        vector<int> existmod(val, -1);
        for (int i = 0; i <= x; i++) {
            if (dp[i][j] == 1) existmod[i % val] = i;
            if (existmod[i % val] == -1 ||
                (i - existmod[i % val]) / val > fre) {
                dp[i][j + 1] = false;
            } else {
                dp[i][j + 1] = true;
                parent[i][j + 1] = (i - existmod[i % val]) / val;
            }
        }
        // for (int i = 0; i <= x; i++) cout << dp[i][j + 1] << " \n"[i == x];
    }

    /*for (int j = 0; j < (int)freq.size(); j++) {
        for (int i = 0; i <= x; i++) cout << parent[i][j + 1] << " \n"[i == x];
    }*/

    if (dp[x][(int)freq.size()]) {
        string ans(n, b.sc);
        cout << depmax + 1 << '\n';
        int i = x, j = (int)freq.size();
        while (i != 0) {
            assert(j > 0);
            int val = depcnt_values[j - 1].fr;
            vector<vector<int>> &vvec = depcnt_values[j - 1].sc;
            int use = parent[i][j];
            i -= use * val;
            j--;
            while (use--) {
                assert(!vvec.empty());
                auto vec = vvec.back();
                for (int idx : vec) {
                    // cout << idx << ' ';
                    ans[idx] = a.sc;
                }
                // cout << '\n';
                vvec.pop_back();
            }
        }
        cout << ans << '\n';
        return;
    }
    string ans(n, '?');
    cout << depmax + 2 << '\n';
    for (int h = 0; h <= depmax; h++) {
        vector<int> &vec = depcnt_idx[h].sc;
        int cnt = depcnt_idx[h].fr;

        sort(vec.begin(), vec.end(),
             [&](const int &a, const int &b) { return sz[a] > sz[b]; });
        if (a.fr < b.fr) swap(a, b);
        assert(a.fr != 0);
        for (int idx : vec) {
            if (a.fr == 0) swap(a, b);
            ans[idx] = a.sc;
            a.fr--;
        }
    }
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t;
    t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}
