197612025-12-22 09:35:17szabel26Hírlánccpp17Időlimit túllépés 20/80600ms5684 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;
}

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)
        {
            bejar(i);
            if (hossz > sol.second)
            {
                sol.first = i;
                sol.second = hossz;
            }
            hossz = 0;
        }
    }
    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
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva1ms316 KiB
subtask220/20
2Elfogadva2ms512 KiB
3Elfogadva2ms316 KiB
4Elfogadva2ms508 KiB
5Elfogadva3ms316 KiB
6Elfogadva3ms368 KiB
7Elfogadva3ms508 KiB
8Elfogadva4ms316 KiB
9Elfogadva7ms316 KiB
10Elfogadva3ms340 KiB
11Elfogadva9ms316 KiB
12Elfogadva12ms316 KiB
subtask30/18
13Elfogadva287ms2756 KiB
14Időlimit túllépés586ms2612 KiB
15Időlimit túllépés586ms2760 KiB
16Időlimit túllépés586ms2752 KiB
17Időlimit túllépés574ms3524 KiB
18Időlimit túllépés588ms3788 KiB
19Időlimit túllépés588ms3640 KiB
20Időlimit túllépés587ms3636 KiB
21Időlimit túllépés583ms5176 KiB
22Időlimit túllépés578ms5684 KiB
subtask40/42
23Elfogadva1ms316 KiB
24Elfogadva2ms512 KiB
25Elfogadva2ms316 KiB
26Elfogadva2ms508 KiB
27Elfogadva3ms316 KiB
28Elfogadva3ms368 KiB
29Elfogadva3ms508 KiB
30Elfogadva4ms316 KiB
31Elfogadva7ms316 KiB
32Elfogadva3ms340 KiB
33Elfogadva9ms316 KiB
34Elfogadva12ms316 KiB
35Elfogadva287ms2756 KiB
36Időlimit túllépés586ms2612 KiB
37Időlimit túllépés586ms2760 KiB
38Időlimit túllépés586ms2752 KiB
39Időlimit túllépés574ms3524 KiB
40Időlimit túllépés588ms3788 KiB
41Időlimit túllépés588ms3640 KiB
42Időlimit túllépés587ms3636 KiB
43Időlimit túllépés583ms5176 KiB
44Időlimit túllépés578ms5684 KiB
45Elfogadva105ms3396 KiB
46Elfogadva361ms3248 KiB
47Időlimit túllépés589ms3244 KiB
48Időlimit túllépés600ms3248 KiB
49Időlimit túllépés580ms3248 KiB
50Időlimit túllépés580ms3500 KiB
51Időlimit túllépés586ms3504 KiB
52Időlimit túllépés600ms3512 KiB
53Időlimit túllépés591ms3756 KiB
54Időlimit túllépés584ms4012 KiB