41462023-03-15 14:53:23kristofElágazás nélküli úton levő települések (50 pont)python3Runtime error 0/50136ms23428 KiB
from collections import defaultdict

tole = 0
elozo = ""

ki = []

def szomszed(froma):
    global tole
    global elozo
    if (len(graf[froma])) < 3:
        #print(froma)
        tole += 1
        if graf[froma][0] == elozo:
            ki.append(froma)
            elozo = froma
            return szomszed(graf[froma][1])
        else:
            return szomszed(graf[froma][0])
    ki.append(froma)
    return 0

n, m = list(map(int, input().split()))
graf = defaultdict(list)
arr = [0 for i in range(n)]

for i in range(m):
    honnan, hova = list(map(int, input().split()))
    graf[honnan].append(hova)
    graf[hova].append(honnan)
    arr[honnan-1] += 1
    arr[hova-1] += 1

zsakfalvak = [i+1 for i, value in enumerate(arr) if value == 1]

asd = 0

for i in zsakfalvak:
    elozo = i
    szomszed(i)
    asd += tole
    tole = 0

print(asd)
print(*ki.sort())
SubtaskSumTestVerdictTimeMemory
base0/50
1Runtime error0/020ms12040 KiB
2Runtime error0/0134ms21000 KiB
3Runtime error0/219ms12464 KiB
4Runtime error0/220ms12960 KiB
5Runtime error0/219ms13156 KiB
6Runtime error0/219ms13416 KiB
7Runtime error0/219ms13476 KiB
8Runtime error0/228ms14004 KiB
9Runtime error0/237ms15272 KiB
10Runtime error0/250ms16308 KiB
11Runtime error0/276ms18160 KiB
12Runtime error0/279ms18908 KiB
13Runtime error0/327ms14892 KiB
14Runtime error0/334ms17204 KiB
15Runtime error0/335ms15908 KiB
16Runtime error0/337ms16144 KiB
17Runtime error0/371ms18268 KiB
18Runtime error0/374ms18684 KiB
19Runtime error0/386ms19904 KiB
20Runtime error0/3131ms22520 KiB
21Runtime error0/3136ms22852 KiB
22Runtime error0/3135ms23428 KiB