13832022-08-30 11:38:18sangerafSzínes facpp17Accepted 50/50155ms44780 KiB
#include<bits/stdc++.h>
using namespace std;

vector<vector<int>> g;
vector<int> mely;
int minmely=200001;

void dfs(int csucs){
    if(g[csucs].size()==0) minmely=min(mely[csucs], minmely);
    for(int x : g[csucs]){
        mely[x]=mely[csucs]+1;
        dfs(x);
    }
    return;
}

int main(){
    int n;
    cin >> n;
    mely.resize(n+1, 1);
    g.resize(n+1);
    for(int i=2; i<=n; i++){
        int x;
        cin >> x;
        g[x].push_back(i);
    }
    dfs(1);
    cout << minmely << endl;
    for(int i=1; i<=n; i++){
        cout << mely[i]%minmely+1 << " ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1880 KiB
2Accepted0/07ms2944 KiB
3Accepted1/12ms2172 KiB
4Accepted4/42ms2380 KiB
5Accepted5/5119ms44780 KiB
6Accepted2/2136ms21712 KiB
7Accepted3/3134ms21660 KiB
8Accepted2/2133ms21336 KiB
9Accepted2/2126ms20340 KiB
10Accepted2/2128ms21052 KiB
11Accepted2/2133ms23784 KiB
12Accepted2/2143ms25588 KiB
13Accepted2/2137ms26208 KiB
14Accepted2/2148ms26452 KiB
15Accepted2/2138ms27052 KiB
16Accepted2/2137ms27368 KiB
17Accepted2/2140ms27340 KiB
18Accepted2/2140ms27608 KiB
19Accepted2/2140ms27860 KiB
20Accepted2/2153ms27940 KiB
21Accepted2/2155ms28112 KiB
22Accepted2/2143ms28632 KiB
23Accepted2/2146ms32444 KiB
24Accepted3/3149ms37172 KiB