41432023-03-15 14:00:31kristofElágazás nélküli úton levő települések (50 pont)python3Wrong answer 4/50136ms23496 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)
SubtaskSumTestVerdictTimeMemory
base4/50
1Accepted0/020ms11980 KiB
2Wrong answer0/0135ms20872 KiB
3Runtime error0/219ms12608 KiB
4Wrong answer0/220ms12724 KiB
5Accepted2/220ms12900 KiB
6Runtime error0/220ms13152 KiB
7Wrong answer0/219ms13176 KiB
8Wrong answer0/229ms14008 KiB
9Wrong answer0/237ms14764 KiB
10Wrong answer0/250ms15800 KiB
11Accepted2/276ms18024 KiB
12Wrong answer0/275ms18072 KiB
13Wrong answer0/327ms13940 KiB
14Runtime error0/335ms16936 KiB
15Runtime error0/337ms15336 KiB
16Runtime error0/337ms16016 KiB
17Runtime error0/368ms18376 KiB
18Runtime error0/376ms18620 KiB
19Wrong answer0/387ms19804 KiB
20Wrong answer0/3136ms22672 KiB
21Wrong answer0/3135ms22896 KiB
22Wrong answer0/3136ms23496 KiB