#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;
}| Subtask | Sum | Test | Verdict | Time | Memory | ||
|---|---|---|---|---|---|---|---|
| subtask1 | 0/0 | ||||||
| 1 | Accepted | 1ms | 316 KiB | ||||
| subtask2 | 0/20 | ||||||
| 2 | Accepted | 100ms | 15924 KiB | ||||
| 3 | Accepted | 155ms | 16064 KiB | ||||
| 4 | Accepted | 490ms | 15868 KiB | ||||
| 5 | Time limit exceeded | 601ms | 15852 KiB | ||||
| 6 | Time limit exceeded | 587ms | 15924 KiB | ||||
| 7 | Time limit exceeded | 574ms | 15924 KiB | ||||
| 8 | Time limit exceeded | 587ms | 15924 KiB | ||||
| 9 | Time limit exceeded | 587ms | 15924 KiB | ||||
| 10 | Accepted | 432ms | 15924 KiB | ||||
| 11 | Time limit exceeded | 584ms | 15872 KiB | ||||
| 12 | Time limit exceeded | 577ms | 15924 KiB | ||||
| subtask3 | 0/18 | ||||||
| 13 | Runtime error | 71ms | 1832 KiB | ||||
| 14 | Runtime error | 76ms | 2100 KiB | ||||
| 15 | Runtime error | 71ms | 1844 KiB | ||||
| 16 | Runtime error | 71ms | 1844 KiB | ||||
| 17 | Runtime error | 71ms | 1816 KiB | ||||
| 18 | Runtime error | 71ms | 1844 KiB | ||||
| 19 | Runtime error | 71ms | 1856 KiB | ||||
| 20 | Runtime error | 71ms | 1844 KiB | ||||
| 21 | Runtime error | 74ms | 1844 KiB | ||||
| 22 | Runtime error | 71ms | 1796 KiB | ||||
| subtask4 | 0/42 | ||||||
| 23 | Accepted | 1ms | 316 KiB | ||||
| 24 | Accepted | 100ms | 15924 KiB | ||||
| 25 | Accepted | 155ms | 16064 KiB | ||||
| 26 | Accepted | 490ms | 15868 KiB | ||||
| 27 | Time limit exceeded | 601ms | 15852 KiB | ||||
| 28 | Time limit exceeded | 587ms | 15924 KiB | ||||
| 29 | Time limit exceeded | 574ms | 15924 KiB | ||||
| 30 | Time limit exceeded | 587ms | 15924 KiB | ||||
| 31 | Time limit exceeded | 587ms | 15924 KiB | ||||
| 32 | Accepted | 432ms | 15924 KiB | ||||
| 33 | Time limit exceeded | 584ms | 15872 KiB | ||||
| 34 | Time limit exceeded | 577ms | 15924 KiB | ||||
| 35 | Runtime error | 71ms | 1832 KiB | ||||
| 36 | Runtime error | 76ms | 2100 KiB | ||||
| 37 | Runtime error | 71ms | 1844 KiB | ||||
| 38 | Runtime error | 71ms | 1844 KiB | ||||
| 39 | Runtime error | 71ms | 1816 KiB | ||||
| 40 | Runtime error | 71ms | 1844 KiB | ||||
| 41 | Runtime error | 71ms | 1856 KiB | ||||
| 42 | Runtime error | 71ms | 1844 KiB | ||||
| 43 | Runtime error | 74ms | 1844 KiB | ||||
| 44 | Runtime error | 71ms | 1796 KiB | ||||
| 45 | Runtime error | 71ms | 1848 KiB | ||||
| 46 | Runtime error | 71ms | 1844 KiB | ||||
| 47 | Runtime error | 71ms | 1844 KiB | ||||
| 48 | Runtime error | 71ms | 1808 KiB | ||||
| 49 | Runtime error | 71ms | 1844 KiB | ||||
| 50 | Runtime error | 71ms | 1784 KiB | ||||
| 51 | Runtime error | 71ms | 1844 KiB | ||||
| 52 | Runtime error | 71ms | 1856 KiB | ||||
| 53 | Runtime error | 71ms | 1844 KiB | ||||
| 54 | Runtime error | 71ms | 1848 KiB | ||||