197752025-12-22 14:49:59szabel26Hírlánccpp17Wrong answer 0/80600ms4016 KiB
// hirlanc.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;

struct adat {
    int be, sz;
    bool lat;
};

vector<adat>x;
vector<int>csp;

pair<int, int>sol;

int n, hossz;

void bejar(int akt)
{
    x[akt].lat = true;
    ++hossz;
    if (x[x[akt].sz].lat == false)
    {
        bejar(x[akt].sz);
    }
    x[akt].lat = false;
    return;
}

void kor(int akt, int kezd)
{
    x[akt].lat = true;
    ++hossz;
    if (x[x[akt].sz].lat == false)
    {
        kor(x[akt].sz, kezd);
    }
}

int main()
{
    cin >> n;

    x.resize(n + 1, { 0,0,0 });
    int a = 0;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a;
        x[i].sz = a;
        x[a].be = i;
    }

    for (int i = 1; i <= n; ++i)
    {
        if (x[i].be == 0)
        {
            csp.push_back(i);
        }
    }

    sol.first = 0;
    sol.second = 0;
    if (!csp.empty())
    {
        for (auto& e : csp)
        {
            bejar(e);
            if (hossz > sol.second)
            {
                sol.first = e;
                sol.second = hossz;
            }
            hossz = 0;
        }
    }
    else
    {
        for (int i = 1; i <= n; ++i)
        {
            if (x[i].lat == false)
            {
                kor(i, i);
                if (hossz > sol.second)
                {
                    sol.first = i;
                    sol.second = hossz;
                }
            }
        }
    }
    cout << sol.first << " " << sol.second;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
subtask20/20
2Accepted1ms508 KiB
3Accepted2ms548 KiB
4Accepted2ms316 KiB
5Accepted3ms316 KiB
6Accepted3ms316 KiB
7Accepted3ms316 KiB
8Accepted4ms316 KiB
9Accepted7ms316 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms316 KiB
12Wrong answer1ms316 KiB
subtask30/18
13Wrong answer81ms2752 KiB
14Wrong answer79ms2580 KiB
15Wrong answer78ms2760 KiB
16Wrong answer79ms2756 KiB
17Wrong answer79ms2612 KiB
18Wrong answer78ms2612 KiB
19Wrong answer78ms2612 KiB
20Wrong answer79ms2796 KiB
21Wrong answer78ms2864 KiB
22Accepted78ms2804 KiB
subtask40/42
23Accepted1ms508 KiB
24Accepted1ms508 KiB
25Accepted2ms548 KiB
26Accepted2ms316 KiB
27Accepted3ms316 KiB
28Accepted3ms316 KiB
29Accepted3ms316 KiB
30Accepted4ms316 KiB
31Accepted7ms316 KiB
32Wrong answer1ms316 KiB
33Wrong answer1ms316 KiB
34Wrong answer1ms316 KiB
35Wrong answer81ms2752 KiB
36Wrong answer79ms2580 KiB
37Wrong answer78ms2760 KiB
38Wrong answer79ms2756 KiB
39Wrong answer79ms2612 KiB
40Wrong answer78ms2612 KiB
41Wrong answer78ms2612 KiB
42Wrong answer79ms2796 KiB
43Wrong answer78ms2864 KiB
44Accepted78ms2804 KiB
45Accepted103ms3244 KiB
46Accepted381ms3396 KiB
47Time limit exceeded584ms3392 KiB
48Time limit exceeded600ms3404 KiB
49Time limit exceeded582ms3248 KiB
50Time limit exceeded583ms3512 KiB
51Time limit exceeded579ms3504 KiB
52Time limit exceeded600ms3504 KiB
53Time limit exceeded586ms3908 KiB
54Time limit exceeded577ms4016 KiB