41652023-03-15 18:27:57kristofElágazás nélküli úton levő települések (50 pont)python3Wrong answer 2/50136ms23472 KiB
from collections import defaultdict

"""def elerheto(honnan, mostani):
    kiElerheto.append(mostani)
    if len(graf[mostani]) <= 2:
        if graf[mostani][0] != honnan:
            elerheto(mostani, graf[mostani][0])
        else:
            elerheto(mostani, graf[mostani][1])"""



n, m = list(map(int, input().split()))
graf = defaultdict(list)

kiElerheto = []
kiSzamlalo = 0


#todo Is there a way without array?
arr = [0 for i in range(n)]

for i in range(m):
    honnan1, hova = list(map(int, input().split()))

    graf[honnan1].append(hova)
    graf[hova].append(honnan1)

    arr[honnan1-1] += 1
    arr[hova-1] += 1

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

for i in zsakfalvak:
    if len(graf[i]) == 1:
        pass


print(len(kiElerheto))
print(*sorted(kiElerheto))
SubtaskSumTestVerdictTimeMemory
base2/50
1Wrong answer0/020ms11880 KiB
2Wrong answer0/0136ms20956 KiB
3Wrong answer0/220ms12376 KiB
4Wrong answer0/219ms12380 KiB
5Accepted2/220ms12632 KiB
6Wrong answer0/219ms12636 KiB
7Wrong answer0/219ms12872 KiB
8Wrong answer0/228ms14004 KiB
9Wrong answer0/237ms15124 KiB
10Wrong answer0/250ms16156 KiB
11Wrong answer0/275ms18228 KiB
12Wrong answer0/275ms18360 KiB
13Wrong answer0/326ms14888 KiB
14Wrong answer0/332ms15712 KiB
15Wrong answer0/335ms16368 KiB
16Wrong answer0/335ms16968 KiB
17Wrong answer0/364ms18816 KiB
18Wrong answer0/370ms19496 KiB
19Wrong answer0/385ms20244 KiB
20Wrong answer0/3129ms22892 KiB
21Wrong answer0/3135ms23448 KiB
22Wrong answer0/3134ms23472 KiB