// 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
| Subtask | Sum | Test | Verdict | Time | Memory | ||
|---|---|---|---|---|---|---|---|
| subtask1 | 0/0 | ||||||
| 1 | Accepted | 1ms | 316 KiB | ||||
| subtask2 | 20/20 | ||||||
| 2 | Accepted | 2ms | 512 KiB | ||||
| 3 | Accepted | 2ms | 316 KiB | ||||
| 4 | Accepted | 2ms | 316 KiB | ||||
| 5 | Accepted | 2ms | 316 KiB | ||||
| 6 | Accepted | 2ms | 652 KiB | ||||
| 7 | Accepted | 2ms | 316 KiB | ||||
| 8 | Accepted | 2ms | 508 KiB | ||||
| 9 | Accepted | 2ms | 316 KiB | ||||
| 10 | Accepted | 2ms | 316 KiB | ||||
| 11 | Accepted | 1ms | 316 KiB | ||||
| 12 | Accepted | 1ms | 492 KiB | ||||
| subtask3 | 0/18 | ||||||
| 13 | Time limit exceeded | 598ms | 3548 KiB | ||||
| 14 | Time limit exceeded | 600ms | 3540 KiB | ||||
| 15 | Accepted | 254ms | 3544 KiB | ||||
| 16 | Accepted | 120ms | 3536 KiB | ||||
| 17 | Accepted | 85ms | 3524 KiB | ||||
| 18 | Accepted | 81ms | 3448 KiB | ||||
| 19 | Accepted | 79ms | 3448 KiB | ||||
| 20 | Accepted | 79ms | 3444 KiB | ||||
| 21 | Accepted | 79ms | 3400 KiB | ||||
| 22 | Accepted | 78ms | 3360 KiB | ||||
| subtask4 | 0/42 | ||||||
| 23 | Accepted | 1ms | 508 KiB | ||||
| 24 | Accepted | 2ms | 512 KiB | ||||
| 25 | Accepted | 2ms | 316 KiB | ||||
| 26 | Accepted | 2ms | 316 KiB | ||||
| 27 | Accepted | 2ms | 316 KiB | ||||
| 28 | Accepted | 2ms | 652 KiB | ||||
| 29 | Accepted | 2ms | 316 KiB | ||||
| 30 | Accepted | 2ms | 508 KiB | ||||
| 31 | Accepted | 2ms | 316 KiB | ||||
| 32 | Accepted | 2ms | 316 KiB | ||||
| 33 | Accepted | 1ms | 316 KiB | ||||
| 34 | Accepted | 1ms | 492 KiB | ||||
| 35 | Time limit exceeded | 598ms | 3548 KiB | ||||
| 36 | Time limit exceeded | 600ms | 3540 KiB | ||||
| 37 | Accepted | 254ms | 3544 KiB | ||||
| 38 | Accepted | 120ms | 3536 KiB | ||||
| 39 | Accepted | 85ms | 3524 KiB | ||||
| 40 | Accepted | 81ms | 3448 KiB | ||||
| 41 | Accepted | 79ms | 3448 KiB | ||||
| 42 | Accepted | 79ms | 3444 KiB | ||||
| 43 | Accepted | 79ms | 3400 KiB | ||||
| 44 | Accepted | 78ms | 3360 KiB | ||||
| 45 | Time limit exceeded | 587ms | 3536 KiB | ||||
| 46 | Time limit exceeded | 587ms | 3536 KiB | ||||
| 47 | Time limit exceeded | 587ms | 3540 KiB | ||||
| 48 | Time limit exceeded | 600ms | 3544 KiB | ||||
| 49 | Time limit exceeded | 578ms | 3540 KiB | ||||
| 50 | Time limit exceeded | 578ms | 3536 KiB | ||||
| 51 | Time limit exceeded | 578ms | 3552 KiB | ||||
| 52 | Time limit exceeded | 600ms | 3536 KiB | ||||
| 53 | Time limit exceeded | 584ms | 3548 KiB | ||||
| 54 | Time limit exceeded | 584ms | 3552 KiB | ||||