231042026-01-16 12:15:16BravoHírlánccpp17Time limit exceeded 0/80601ms16092 KiB
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;

int main()
{
    //ifstream f("csm.txt");
    int n;
    cin >> n;
    int a[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
             a[i][j]=0;
        }
    }
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        a[i][x-1]=1;
    }
    queue <int> q;
    int tav[n]={0};
    for(int i=0;i<n;i++){
        int x;
        int c=0;
        x=i;
        q.push(x);
        int volt[n]={0};
        volt[x]=1;
        while(!q.empty()){
            x=q.front();
            q.pop();
            for(int j=0;j<n;j++){
                if(a[x][j]==1 && volt[j]!=1){
                    volt[j]=1;
                    q.push(j);
                    c++;
                }
            }
        }
        tav[i]=c;
    }
    int c=0,z;
    for(int i=0;i<n;i++){
        if(tav[i]>c){
            c=tav[i];
            z=i;
        }
    }
    cout << z+1 << " " << c+1;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms508 KiB
subtask20/20
2Accepted67ms15928 KiB
3Accepted112ms16064 KiB
4Accepted340ms16092 KiB
5Time limit exceeded601ms15924 KiB
6Time limit exceeded583ms15924 KiB
7Time limit exceeded579ms15924 KiB
8Time limit exceeded592ms15924 KiB
9Time limit exceeded573ms15924 KiB
10Accepted296ms15924 KiB
11Time limit exceeded588ms15924 KiB
12Time limit exceeded578ms15928 KiB
subtask30/18
13Runtime error2ms316 KiB
14Runtime error2ms316 KiB
15Runtime error2ms316 KiB
16Runtime error1ms568 KiB
17Runtime error1ms316 KiB
18Runtime error1ms316 KiB
19Runtime error1ms316 KiB
20Runtime error2ms316 KiB
21Runtime error1ms316 KiB
22Runtime error2ms316 KiB
subtask40/42
23Accepted1ms316 KiB
24Accepted67ms15928 KiB
25Accepted112ms16064 KiB
26Accepted340ms16092 KiB
27Time limit exceeded601ms15924 KiB
28Time limit exceeded583ms15924 KiB
29Time limit exceeded579ms15924 KiB
30Time limit exceeded592ms15924 KiB
31Time limit exceeded573ms15924 KiB
32Accepted296ms15924 KiB
33Time limit exceeded588ms15924 KiB
34Time limit exceeded578ms15928 KiB
35Runtime error2ms316 KiB
36Runtime error2ms316 KiB
37Runtime error2ms316 KiB
38Runtime error1ms568 KiB
39Runtime error1ms316 KiB
40Runtime error1ms316 KiB
41Runtime error1ms316 KiB
42Runtime error2ms316 KiB
43Runtime error1ms316 KiB
44Runtime error2ms316 KiB
45Runtime error1ms316 KiB
46Runtime error1ms316 KiB
47Runtime error2ms316 KiB
48Runtime error1ms316 KiB
49Runtime error1ms316 KiB
50Runtime error1ms316 KiB
51Runtime error1ms316 KiB
52Runtime error1ms316 KiB
53Runtime error1ms316 KiB
54Runtime error1ms316 KiB