210942026-01-12 11:31:16SzBeatrixHírlánccpp17Time limit exceeded 0/80601ms16064 KiB
#include <iostream>
#include <queue>

using namespace std;

int main()
{
    int N, c;
    cin>>N;
    int a[N];
    queue<int> q;
    for(int i=0; i<N; i++)
    {
        cin>>a[i];a[i]--;
    }
    int v[N]={0};
    int b[N][N]={0};
    for(int i=0; i<N; i++)
    {
        for(int j=0; j<N; j++)
        {
            b[i][j]=0;
        }
    }
    for(int i=0; i<N; i++)
    {
        c=a[i];
        b[i][c]=1;
    }
    int maxim=0, x, db=0, db2=0;
    for(int i=0; i<N; i++)
    {
        fill(v, v+N,0);
        q.push(i);
        v[i]=1;
        while(!q.empty())
        {
            x=q.front();
            q.pop();
            for(int y=0; y<N; y++)
            {
                if(b[x][y]==1&&v[y]==0)
                {
                    q.push(y);
                    v[y]=1;
                    db++;
                }
            }
            if(db>maxim)
            {
                maxim=db;
                db2=i;
            }
        }
        db=0;
    }
    cout<<db2+1<<" "<<maxim+1;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
subtask20/20
2Accepted100ms15924 KiB
3Accepted155ms16064 KiB
4Accepted490ms15868 KiB
5Time limit exceeded601ms15852 KiB
6Time limit exceeded587ms15924 KiB
7Time limit exceeded574ms15924 KiB
8Time limit exceeded587ms15924 KiB
9Time limit exceeded587ms15924 KiB
10Accepted432ms15924 KiB
11Time limit exceeded584ms15872 KiB
12Time limit exceeded577ms15924 KiB
subtask30/18
13Runtime error71ms1832 KiB
14Runtime error76ms2100 KiB
15Runtime error71ms1844 KiB
16Runtime error71ms1844 KiB
17Runtime error71ms1816 KiB
18Runtime error71ms1844 KiB
19Runtime error71ms1856 KiB
20Runtime error71ms1844 KiB
21Runtime error74ms1844 KiB
22Runtime error71ms1796 KiB
subtask40/42
23Accepted1ms316 KiB
24Accepted100ms15924 KiB
25Accepted155ms16064 KiB
26Accepted490ms15868 KiB
27Time limit exceeded601ms15852 KiB
28Time limit exceeded587ms15924 KiB
29Time limit exceeded574ms15924 KiB
30Time limit exceeded587ms15924 KiB
31Time limit exceeded587ms15924 KiB
32Accepted432ms15924 KiB
33Time limit exceeded584ms15872 KiB
34Time limit exceeded577ms15924 KiB
35Runtime error71ms1832 KiB
36Runtime error76ms2100 KiB
37Runtime error71ms1844 KiB
38Runtime error71ms1844 KiB
39Runtime error71ms1816 KiB
40Runtime error71ms1844 KiB
41Runtime error71ms1856 KiB
42Runtime error71ms1844 KiB
43Runtime error74ms1844 KiB
44Runtime error71ms1796 KiB
45Runtime error71ms1848 KiB
46Runtime error71ms1844 KiB
47Runtime error71ms1844 KiB
48Runtime error71ms1808 KiB
49Runtime error71ms1844 KiB
50Runtime error71ms1784 KiB
51Runtime error71ms1844 KiB
52Runtime error71ms1856 KiB
53Runtime error71ms1844 KiB
54Runtime error71ms1848 KiB