79132024-01-11 22:21:28KezdőElágazás nélküli úton levő települések (50 pont)python3Accepted 50/5078ms25068 KiB
from sys import stdin

def main():
    N,M = [int(i) for i in input().split()]
    U = [[] for i in range(N+1)]
    for i in range(M):
        a,b = [int(i) for i in stdin.readline().split()]
        U[a].append(b)
        U[b].append(a)

    zsak = [i for i in range(1,N+1) if len(U[i]) == 1]

    ent = []   # elágazás nélküli települések
    for zs in zsak:
        z = zs
        ut = U[z][:]
        while len(ut) == 1:
            falu = ut[0]
            if falu not in ent:
                ent.append(falu)
            ut = U[falu][:]
            ut.remove(z)
            z = falu

    print(len(ent))
    if ent != []:
        ent.sort()
        print(*ent)
main()    
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/017ms11672 KiB
2Accepted0/078ms20512 KiB
3Accepted2/217ms12524 KiB
4Accepted2/217ms12916 KiB
5Accepted2/217ms12792 KiB
6Accepted2/217ms13020 KiB
7Accepted2/217ms13332 KiB
8Accepted2/221ms13696 KiB
9Accepted2/227ms15032 KiB
10Accepted2/232ms15876 KiB
11Accepted2/245ms18128 KiB
12Accepted2/248ms18760 KiB
13Accepted3/320ms15208 KiB
14Accepted3/325ms15912 KiB
15Accepted3/327ms16324 KiB
16Accepted3/345ms17168 KiB
17Accepted3/343ms19216 KiB
18Accepted3/345ms19468 KiB
19Accepted3/350ms20740 KiB
20Accepted3/371ms24056 KiB
21Accepted3/374ms24664 KiB
22Accepted3/374ms25068 KiB