231052026-01-16 12:15:50BravoHírlánccpp17Time limit exceeded 0/80600ms16116 KiB
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;

int main()
{
    ios_base::sync_with_stdio();
    cin.tie();
    cout.tie();
    //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
1Accepted1ms316 KiB
subtask20/20
2Accepted71ms15972 KiB
3Accepted112ms16064 KiB
4Accepted335ms15900 KiB
5Time limit exceeded600ms15856 KiB
6Time limit exceeded584ms15924 KiB
7Time limit exceeded578ms15924 KiB
8Time limit exceeded584ms15924 KiB
9Time limit exceeded583ms15924 KiB
10Accepted314ms16116 KiB
11Time limit exceeded592ms15924 KiB
12Time limit exceeded592ms15924 KiB
subtask30/18
13Runtime error2ms316 KiB
14Runtime error2ms316 KiB
15Runtime error2ms564 KiB
16Runtime error2ms316 KiB
17Runtime error1ms316 KiB
18Runtime error1ms564 KiB
19Runtime error1ms316 KiB
20Runtime error1ms316 KiB
21Runtime error1ms316 KiB
22Runtime error1ms316 KiB
subtask40/42
23Accepted1ms500 KiB
24Accepted71ms15972 KiB
25Accepted112ms16064 KiB
26Accepted335ms15900 KiB
27Time limit exceeded600ms15856 KiB
28Time limit exceeded584ms15924 KiB
29Time limit exceeded578ms15924 KiB
30Time limit exceeded584ms15924 KiB
31Time limit exceeded583ms15924 KiB
32Accepted314ms16116 KiB
33Time limit exceeded592ms15924 KiB
34Time limit exceeded592ms15924 KiB
35Runtime error2ms316 KiB
36Runtime error2ms316 KiB
37Runtime error2ms564 KiB
38Runtime error2ms316 KiB
39Runtime error1ms316 KiB
40Runtime error1ms564 KiB
41Runtime error1ms316 KiB
42Runtime error1ms316 KiB
43Runtime error1ms316 KiB
44Runtime error1ms316 KiB
45Runtime error1ms400 KiB
46Runtime error1ms316 KiB
47Runtime error1ms316 KiB
48Runtime error1ms328 KiB
49Runtime error1ms316 KiB
50Runtime error1ms316 KiB
51Runtime error1ms508 KiB
52Runtime error1ms316 KiB
53Runtime error1ms316 KiB
54Runtime error1ms316 KiB