188062025-11-05 09:11:11csdavidHírlánccpp17Wrong answer 0/80600ms2932 KiB
#include <iostream>
#include <queue>
using namespace std;

struct node{
    int kovetkezo, bejart=-1, x=0;
};

node a[200000];
int n, y;


int dfs(int& h){
    //cout << '"' << h << '"';
    int l=0;
    int x=h;
    while(a[x].bejart!=h){
        //cout << x << ' ' << a[x].kovetkezo << '\n';
        a[x].bejart=h;
        x=a[x].kovetkezo;
        l++;
    }
    return l;
}

int main()
{
    int maxi=-1, maxind;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i].kovetkezo;
        a[i].kovetkezo--;
        a[a[i].kovetkezo].x++;
    }

    bool d=1;
    for(int i=0; i<n; i++){
        //cout << i+1 << ": " << a[i].x << '\n';
        if(a[i].x==0){
            d=0;
            int t=dfs(i);
            if(t>maxi){
                maxi=t;
                maxind=i+1;
            }
        }
    }
    if(d){
        cout << 1 << ' ' << n << '\n';
    }
    else{
        cout << maxind << ' ' << maxi << '\n';
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms2612 KiB
subtask20/20
2Accepted3ms2796 KiB
3Accepted3ms2624 KiB
4Accepted4ms2932 KiB
5Accepted4ms2612 KiB
6Accepted4ms2688 KiB
7Accepted4ms2716 KiB
8Accepted4ms2844 KiB
9Accepted4ms2640 KiB
10Wrong answer4ms2744 KiB
11Wrong answer3ms2612 KiB
12Wrong answer3ms2612 KiB
subtask30/18
13Wrong answer71ms2612 KiB
14Wrong answer71ms2804 KiB
15Wrong answer71ms2876 KiB
16Wrong answer71ms2804 KiB
17Wrong answer71ms2856 KiB
18Wrong answer71ms2744 KiB
19Wrong answer71ms2804 KiB
20Wrong answer71ms2804 KiB
21Wrong answer71ms2612 KiB
22Accepted71ms2760 KiB
subtask40/42
23Accepted3ms2612 KiB
24Accepted3ms2796 KiB
25Accepted3ms2624 KiB
26Accepted4ms2932 KiB
27Accepted4ms2612 KiB
28Accepted4ms2688 KiB
29Accepted4ms2716 KiB
30Accepted4ms2844 KiB
31Accepted4ms2640 KiB
32Wrong answer4ms2744 KiB
33Wrong answer3ms2612 KiB
34Wrong answer3ms2612 KiB
35Wrong answer71ms2612 KiB
36Wrong answer71ms2804 KiB
37Wrong answer71ms2876 KiB
38Wrong answer71ms2804 KiB
39Wrong answer71ms2856 KiB
40Wrong answer71ms2744 KiB
41Wrong answer71ms2804 KiB
42Wrong answer71ms2804 KiB
43Wrong answer71ms2612 KiB
44Accepted71ms2760 KiB
45Accepted107ms2744 KiB
46Accepted301ms2804 KiB
47Time limit exceeded592ms2612 KiB
48Time limit exceeded600ms2612 KiB
49Time limit exceeded574ms2612 KiB
50Time limit exceeded589ms2612 KiB
51Time limit exceeded587ms2612 KiB
52Time limit exceeded582ms2612 KiB
53Time limit exceeded586ms2612 KiB
54Time limit exceeded583ms2612 KiB