88912024-02-02 22:18:53radocziaronLegtávolabbi leszármazottpython3Time limit exceeded 13/50379ms13120 KiB
n = int(input())
oszlop1 = []
oszlop2 = []
mag = 0
maxc = -1
gyerekek = []
cucc = 0
szamlalo = 0

for i in range(n-1):
    sor = list(map(int,input().split()))
    oszlop1.append(sor[0])
    oszlop2.append(sor[1])
    
for i in range(1,n+1):
    if i not in oszlop1 :
        gyerekek.append(i)
    elif i not in oszlop2:
        mag = i

for i in range(len(gyerekek)):
    szamlalo = 0
    gyerek = gyerekek[i]
    apa = oszlop1[oszlop2.index(gyerek)]
    while apa != mag: 
        szamlalo += 1
        gyerek = apa
        apa = oszlop1[oszlop2.index(apa)]
    if maxc < szamlalo:
        maxc = szamlalo
        cucc = gyerekek[i]
        
print(cucc)
SubtaskSumTestVerdictTimeMemory
base13/50
1Accepted0/017ms11328 KiB
2Time limit exceeded0/0365ms11124 KiB
3Accepted1/117ms11924 KiB
4Accepted3/317ms11736 KiB
5Accepted3/317ms11936 KiB
6Accepted1/117ms12024 KiB
7Accepted1/117ms12072 KiB
8Accepted1/1228ms12324 KiB
9Time limit exceeded0/2349ms12716 KiB
10Time limit exceeded0/3368ms12660 KiB
11Accepted3/327ms12548 KiB
12Time limit exceeded0/4365ms12636 KiB
13Time limit exceeded0/4379ms12704 KiB
14Time limit exceeded0/3375ms5880 KiB
15Time limit exceeded0/3372ms12268 KiB
16Time limit exceeded0/3363ms11916 KiB
17Time limit exceeded0/3375ms12572 KiB
18Time limit exceeded0/4379ms10852 KiB
19Time limit exceeded0/4360ms11892 KiB
20Time limit exceeded0/4379ms13120 KiB