195262025-12-12 16:31:47szabelrHírlánccpp17Időlimit túllépés 20/80600ms3552 KiB
// hirlanc.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <map>
#include <vector>
#include <unordered_map>
#include <set>
using namespace std;

int main()
{
    int n,x,tanulo=1;
    cin >> n;
    vector<int> pairs(n+1);

    int best[200001];
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        pairs[i]=x;
        best[i] = 0;
    }
    
    int maxi = 0;
    
    for (int i = 1; i <= n; i++)
    {
        if (best[i] == 0) {
            int k = i;
            int og = i;
            int count = 0;
            vector<int> pontok(n+1);
            vector<int> hely(n+1,-1);
            while (hely[k]==-1 and best[k]==0)
            {
                pontok[count] = k;
                count++;
                hely[k] = count - 1;
                k = pairs[k];
            }
            if (best[k] != 0)
            {
                int a = best[k] + 1;
                for (int y = count - 1; y >= 0; y--)
                {
                    best[pontok[y]] = a;
                    a++;
                }
            }
            else
            {
                int size = count - hely[k];
                for (int j = hely[k]; j <= count - 1; j++)
                {
                    best[pontok[j]] = size;

                }
                int a = best[k] + 1;
                for (int j = hely[k] - 1; j >= 0; j--)
                {
                    best[pontok[j]] = a;
                    a++;

                }
            }
            
            if (best[i] > maxi)
            {
                maxi = best[i];
                tanulo = i;
            }
        }
    }
    cout << tanulo<<" "<<maxi;
}

// 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
4Elfogadva2ms316 KiB
5Elfogadva2ms316 KiB
6Elfogadva2ms652 KiB
7Elfogadva2ms316 KiB
8Elfogadva2ms508 KiB
9Elfogadva2ms316 KiB
10Elfogadva2ms316 KiB
11Elfogadva1ms316 KiB
12Elfogadva1ms492 KiB
subtask30/18
13Időlimit túllépés598ms3548 KiB
14Időlimit túllépés600ms3540 KiB
15Elfogadva254ms3544 KiB
16Elfogadva120ms3536 KiB
17Elfogadva85ms3524 KiB
18Elfogadva81ms3448 KiB
19Elfogadva79ms3448 KiB
20Elfogadva79ms3444 KiB
21Elfogadva79ms3400 KiB
22Elfogadva78ms3360 KiB
subtask40/42
23Elfogadva1ms508 KiB
24Elfogadva2ms512 KiB
25Elfogadva2ms316 KiB
26Elfogadva2ms316 KiB
27Elfogadva2ms316 KiB
28Elfogadva2ms652 KiB
29Elfogadva2ms316 KiB
30Elfogadva2ms508 KiB
31Elfogadva2ms316 KiB
32Elfogadva2ms316 KiB
33Elfogadva1ms316 KiB
34Elfogadva1ms492 KiB
35Időlimit túllépés598ms3548 KiB
36Időlimit túllépés600ms3540 KiB
37Elfogadva254ms3544 KiB
38Elfogadva120ms3536 KiB
39Elfogadva85ms3524 KiB
40Elfogadva81ms3448 KiB
41Elfogadva79ms3448 KiB
42Elfogadva79ms3444 KiB
43Elfogadva79ms3400 KiB
44Elfogadva78ms3360 KiB
45Időlimit túllépés587ms3536 KiB
46Időlimit túllépés587ms3536 KiB
47Időlimit túllépés587ms3540 KiB
48Időlimit túllépés600ms3544 KiB
49Időlimit túllépés578ms3540 KiB
50Időlimit túllépés578ms3536 KiB
51Időlimit túllépés578ms3552 KiB
52Időlimit túllépés600ms3536 KiB
53Időlimit túllépés584ms3548 KiB
54Időlimit túllépés584ms3552 KiB