188052025-11-05 09:05:20csdavidHírlánccpp11Wrong answer 0/80600ms2940 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, 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
3Wrong answer3ms2612 KiB
4Wrong answer4ms2796 KiB
5Wrong answer4ms2612 KiB
6Wrong answer4ms2748 KiB
7Wrong answer4ms2612 KiB
8Wrong answer4ms2744 KiB
9Accepted4ms2612 KiB
10Wrong answer4ms2808 KiB
11Wrong answer4ms2796 KiB
12Wrong answer3ms2612 KiB
subtask30/18
13Wrong answer75ms2740 KiB
14Wrong answer74ms2748 KiB
15Wrong answer75ms2748 KiB
16Wrong answer75ms2744 KiB
17Wrong answer75ms2612 KiB
18Wrong answer75ms2748 KiB
19Wrong answer75ms2612 KiB
20Wrong answer74ms2612 KiB
21Wrong answer74ms2804 KiB
22Accepted75ms2940 KiB
subtask40/42
23Accepted3ms2612 KiB
24Accepted3ms2796 KiB
25Wrong answer3ms2612 KiB
26Wrong answer4ms2796 KiB
27Wrong answer4ms2612 KiB
28Wrong answer4ms2748 KiB
29Wrong answer4ms2612 KiB
30Wrong answer4ms2744 KiB
31Accepted4ms2612 KiB
32Wrong answer4ms2808 KiB
33Wrong answer4ms2796 KiB
34Wrong answer3ms2612 KiB
35Wrong answer75ms2740 KiB
36Wrong answer74ms2748 KiB
37Wrong answer75ms2748 KiB
38Wrong answer75ms2744 KiB
39Wrong answer75ms2612 KiB
40Wrong answer75ms2748 KiB
41Wrong answer75ms2612 KiB
42Wrong answer74ms2612 KiB
43Wrong answer74ms2804 KiB
44Accepted75ms2940 KiB
45Accepted100ms2612 KiB
46Wrong answer289ms2796 KiB
47Time limit exceeded586ms2500 KiB
48Time limit exceeded600ms2612 KiB
49Time limit exceeded580ms2612 KiB
50Time limit exceeded586ms2612 KiB
51Time limit exceeded582ms2612 KiB
52Time limit exceeded600ms2612 KiB
53Time limit exceeded587ms2612 KiB
54Time limit exceeded577ms2612 KiB