230572026-01-16 11:24:14ZsomiHí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];
		}
	}

	cout << maxi << " " << max;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
subtask20/20
2Accepted2ms316 KiB
3Accepted2ms316 KiB
4Accepted2ms316 KiB
5Accepted3ms316 KiB
6Accepted2ms428 KiB
7Accepted2ms316 KiB
8Accepted3ms424 KiB
9Accepted4ms316 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms316 KiB
12Wrong answer2ms316 KiB
subtask30/18
13Wrong answer71ms1984 KiB
14Wrong answer72ms1980 KiB
15Wrong answer71ms1980 KiB
16Wrong answer71ms1976 KiB
17Wrong answer72ms1844 KiB
18Wrong answer71ms1844 KiB
19Wrong answer71ms1844 KiB
20Wrong answer71ms1984 KiB
21Wrong answer71ms2028 KiB
22Wrong answer72ms1844 KiB
subtask40/42
23Accepted2ms588 KiB
24Accepted2ms316 KiB
25Accepted2ms316 KiB
26Accepted2ms316 KiB
27Accepted3ms316 KiB
28Accepted2ms428 KiB
29Accepted2ms316 KiB
30Accepted3ms424 KiB
31Accepted4ms316 KiB
32Wrong answer1ms316 KiB
33Wrong answer1ms316 KiB
34Wrong answer2ms316 KiB
35Wrong answer71ms1984 KiB
36Wrong answer72ms1980 KiB
37Wrong answer71ms1980 KiB
38Wrong answer71ms1976 KiB
39Wrong answer72ms1844 KiB
40Wrong answer71ms1844 KiB
41Wrong answer71ms1844 KiB
42Wrong answer71ms1984 KiB
43Wrong answer71ms2028 KiB
44Wrong answer72ms1844 KiB
45Accepted108ms2480 KiB
46Accepted208ms2616 KiB
47Time limit exceeded583ms2612 KiB
48Time limit exceeded600ms2616 KiB
49Time limit exceeded586ms2632 KiB
50Time limit exceeded586ms2480 KiB
51Time limit exceeded583ms2356 KiB
52Time limit exceeded580ms2232 KiB
53Time limit exceeded578ms2620 KiB
54Time limit exceeded582ms2480 KiB