191332025-11-25 18:34:26birozsHírláncpypy3Runtime error 0/80142ms47300 KiB
N = int(input())
T = list(map(int,input().split()))
"""
E = []
for i in range(1,N+1):
    if i not in T:
        E.append(i)
maxhossz = 0
volt = [0] * (N+1)
for k in E:
    volt[k] = 1
    sor = [k]
    while T[k-1] not in sor:
        volt[T[k-1]] = 1
        sor.append(T[k-1])
        k = T[k-1]
    if len(sor) > maxhossz:
        maxhossz = len(sor)
        maxkezdo = sor[0]
"""
maxhossz = 0
for i in range(1,N+1):
    if volt[i] == 0:
        hossz = 1
        volt[i] = 1
        kezdo = i
        k = i
        while volt[T[k-1]] == 0:
            hossz += 1
            volt[T[k-1]] = 1
            k = T[k-1]
        if hossz > maxhossz:
            maxhossz = hossz
            maxkezdo = kezdo

print(maxkezdo,maxhossz)

SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error78ms23784 KiB
subtask20/20
2Runtime error79ms23272 KiB
3Runtime error79ms23224 KiB
4Runtime error86ms23456 KiB
5Runtime error86ms23240 KiB
6Runtime error79ms23272 KiB
7Runtime error87ms23268 KiB
8Runtime error78ms23332 KiB
9Runtime error86ms23272 KiB
10Runtime error89ms23264 KiB
11Runtime error76ms23224 KiB
12Runtime error86ms23272 KiB
subtask30/18
13Runtime error137ms47120 KiB
14Runtime error136ms47072 KiB
15Runtime error123ms47216 KiB
16Runtime error123ms47052 KiB
17Runtime error122ms47296 KiB
18Runtime error137ms47244 KiB
19Runtime error136ms47292 KiB
20Runtime error119ms47264 KiB
21Runtime error134ms47296 KiB
22Runtime error119ms47248 KiB
subtask40/42
23Runtime error86ms23256 KiB
24Runtime error79ms23272 KiB
25Runtime error79ms23224 KiB
26Runtime error86ms23456 KiB
27Runtime error86ms23240 KiB
28Runtime error79ms23272 KiB
29Runtime error87ms23268 KiB
30Runtime error78ms23332 KiB
31Runtime error86ms23272 KiB
32Runtime error89ms23264 KiB
33Runtime error76ms23224 KiB
34Runtime error86ms23272 KiB
35Runtime error137ms47120 KiB
36Runtime error136ms47072 KiB
37Runtime error123ms47216 KiB
38Runtime error123ms47052 KiB
39Runtime error122ms47296 KiB
40Runtime error137ms47244 KiB
41Runtime error136ms47292 KiB
42Runtime error119ms47264 KiB
43Runtime error134ms47296 KiB
44Runtime error119ms47248 KiB
45Runtime error120ms47220 KiB
46Runtime error120ms47288 KiB
47Runtime error142ms47244 KiB
48Runtime error137ms47104 KiB
49Runtime error120ms47296 KiB
50Runtime error137ms47296 KiB
51Runtime error119ms47300 KiB
52Runtime error135ms47300 KiB
53Runtime error120ms47240 KiB
54Runtime error119ms47144 KiB