230682026-01-16 11:36:04ZsomiHírlánccpp17Wrong answer 0/80600ms2632 KiB
#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> tanulok(n + 1), a(n + 1), startok;
	for (int i = 1; i < n + 1; i++)
	{
		cin >> tanulok[i];
		a[tanulok[i]]++;
	}

	for (int i = 1; i < n + 1; i++)
	{
		if (a[i] == 0)
			startok.push_back(i);
	}

	//for (auto a : startok)
	//	cout << a;

	int max = 1, maxi = tanulok[1];
	for (int i = 0; i < startok.size(); i++)
	{
		vector<bool> tanulokVolt(n + 1, false);
		int kov = tanulok[startok[i]], most = startok[i], jelenleg = 1;

		while (!tanulokVolt[kov])
		{
			tanulokVolt[most] = true;
			jelenleg++;
			most = kov;
			kov = tanulok[most];
		}

		if (jelenleg > max)
		{
			max = jelenleg;
			maxi = startok[i];
		}
	}
	if (startok.size() == 0)
	{
		max = n;
	}

	cout << maxi << " " << max;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
subtask20/20
2Accepted1ms316 KiB
3Accepted2ms324 KiB
4Accepted2ms316 KiB
5Accepted2ms316 KiB
6Accepted2ms316 KiB
7Accepted2ms316 KiB
8Accepted3ms316 KiB
9Accepted4ms424 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms316 KiB
12Wrong answer2ms508 KiB
subtask30/18
13Wrong answer71ms2036 KiB
14Wrong answer71ms1860 KiB
15Wrong answer71ms1844 KiB
16Wrong answer72ms1844 KiB
17Wrong answer72ms1728 KiB
18Wrong answer71ms1976 KiB
19Wrong answer71ms1844 KiB
20Wrong answer71ms1988 KiB
21Wrong answer72ms1976 KiB
22Accepted71ms1844 KiB
subtask40/42
23Accepted1ms316 KiB
24Accepted1ms316 KiB
25Accepted2ms324 KiB
26Accepted2ms316 KiB
27Accepted2ms316 KiB
28Accepted2ms316 KiB
29Accepted2ms316 KiB
30Accepted3ms316 KiB
31Accepted4ms424 KiB
32Wrong answer1ms316 KiB
33Wrong answer1ms316 KiB
34Wrong answer2ms508 KiB
35Wrong answer71ms2036 KiB
36Wrong answer71ms1860 KiB
37Wrong answer71ms1844 KiB
38Wrong answer72ms1844 KiB
39Wrong answer72ms1728 KiB
40Wrong answer71ms1976 KiB
41Wrong answer71ms1844 KiB
42Wrong answer71ms1988 KiB
43Wrong answer72ms1976 KiB
44Accepted71ms1844 KiB
45Accepted105ms2484 KiB
46Accepted212ms2632 KiB
47Time limit exceeded580ms2480 KiB
48Time limit exceeded600ms2620 KiB
49Time limit exceeded574ms2412 KiB
50Time limit exceeded583ms2480 KiB
51Time limit exceeded574ms2356 KiB
52Time limit exceeded600ms2236 KiB
53Time limit exceeded588ms2484 KiB
54Time limit exceeded588ms2480 KiB