70302023-12-28 09:34:00BenedekMartonSzínes facpp11Wrong answer 0/5078ms9088 KiB
#include <iostream>

using namespace std;

int main()
{
    int n, m=0;
    cin >> n;
    int osv[n-1], szin=0, szt[n], msz;
    bool vov[n];
    for(int i=0; i<n; i++)
    {
        vov[i]=0;
    }
    for(int i=0; i<n-1; i++)
    {
        cin >> osv[i];
        szt[i]=0;
        if(vov[osv[i]]==0)
        {
            vov[osv[i]]=1;
            m++;
        }

    }
    szt[n-1]=0;
    int akt[m], k=0;
    for(int i=0; k<m; i++)
    {
        if(vov[i]==0)
        {
            akt[k]=i;
            k++;
        }
    }
    bool megye=1;
    while(megye)
    {
        szin++;
        for(int i=0; i<m; i++)
        {
            if(szt[akt[i]]==0)
            {
                szt[akt[i]]=szin;
            }
            if(akt[i]==1)
            {
                megye=0;
            }
            akt[i]=osv[akt[i]];
        }
    }
    cout << szin << endl;
    for(int i=0; i<n; i++)
    {
        if(szt[i]==0)
        {
            szt[i]=1;
        }
        cout << szt[i] << " ";
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1752 KiB
2Runtime error0/06ms2328 KiB
3Runtime error0/13ms2224 KiB
4Wrong answer0/43ms2212 KiB
5Runtime error0/575ms7528 KiB
6Runtime error0/278ms7200 KiB
7Runtime error0/376ms7160 KiB
8Runtime error0/278ms7124 KiB
9Runtime error0/278ms6924 KiB
10Runtime error0/278ms6972 KiB
11Runtime error0/276ms7508 KiB
12Runtime error0/276ms7668 KiB
13Runtime error0/275ms7828 KiB
14Runtime error0/275ms7844 KiB
15Runtime error0/275ms8208 KiB
16Runtime error0/276ms8456 KiB
17Runtime error0/275ms8416 KiB
18Runtime error0/275ms8604 KiB
19Runtime error0/275ms8888 KiB
20Runtime error0/275ms8760 KiB
21Runtime error0/274ms9052 KiB
22Runtime error0/275ms9048 KiB
23Runtime error0/275ms9052 KiB
24Runtime error0/375ms9088 KiB