240842026-02-04 08:19:32vyrallLegtávolabbi leszármazottpython3Time limit exceeded 21/50333ms21292 KiB
from functools import cache

n = int(input())
# fw_ind = [[] for _ in range(n)]
bw_ind = [-1] * n
mx, mx_ind = -1, -1
for _ in range(n-1):
    a, f = map(int, input().split())
    # fw_ind[a-1].append(f-1)
    bw_ind[f-1] = a-1


@cache
def calc_dist(node):
    if bw_ind[node] == -1:
        return 1
    else:
        return 1 + calc_dist(bw_ind[node])

for i in range(n):
    c = calc_dist(i)
    if c > mx:
        mx = c
        mx_ind = i + 1

print(mx_ind)
SubtaskSumTestVerdictTimeMemory
base21/50
1Accepted0/020ms3540 KiB
2Accepted0/0270ms17136 KiB
3Accepted1/120ms3888 KiB
4Accepted3/320ms3604 KiB
5Accepted3/320ms3604 KiB
6Accepted1/121ms3588 KiB
7Accepted1/120ms3392 KiB
8Accepted1/124ms3512 KiB
9Accepted2/2280ms17960 KiB
10Accepted3/3296ms17912 KiB
11Accepted3/323ms3504 KiB
12Time limit exceeded0/4333ms20496 KiB
13Time limit exceeded0/4303ms21292 KiB
14Accepted3/346ms4504 KiB
15Runtime error0/3208ms7436 KiB
16Runtime error0/3197ms7348 KiB
17Runtime error0/3209ms7476 KiB
18Runtime error0/4162ms6752 KiB
19Runtime error0/4202ms7128 KiB
20Runtime error0/4228ms7732 KiB