41702023-03-15 18:59:52kristofElágazás nélküli úton levő települések (50 pont)python3Time limit exceeded 28/50263ms23320 KiB
from collections import defaultdict



beenThere = []

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

kiElerheto = set()
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:
    l = graf[i][0]
    kiElerheto.add(l)
    while len(graf[l]) <= 2:
        if graf[l][0] != i:
            kiElerheto.add(graf[l][0])
            l = graf[l][0]
            i = l
        else:
            kiElerheto.add(graf[l][1])
            l = graf[l][1]
            i = l


print(len(kiElerheto))
print(*sorted(kiElerheto))
SubtaskSumTestVerdictTimeMemory
base28/50
1Accepted0/019ms11916 KiB
2Accepted0/0136ms20676 KiB
3Time limit exceeded0/2228ms4584 KiB
4Accepted2/219ms12680 KiB
5Accepted2/219ms12488 KiB
6Runtime error0/219ms13056 KiB
7Accepted2/219ms13316 KiB
8Accepted2/229ms13976 KiB
9Accepted2/237ms14752 KiB
10Accepted2/250ms15712 KiB
11Accepted2/275ms17992 KiB
12Accepted2/279ms18132 KiB
13Time limit exceeded0/3263ms6276 KiB
14Time limit exceeded0/3261ms6848 KiB
15Runtime error0/335ms15952 KiB
16Runtime error0/337ms16068 KiB
17Time limit exceeded0/3238ms8560 KiB
18Runtime error0/370ms18992 KiB
19Accepted3/385ms20128 KiB
20Accepted3/3128ms23012 KiB
21Accepted3/3136ms23220 KiB
22Accepted3/3136ms23320 KiB