41742023-03-15 19:16:06kristofElágazás nélküli úton levő települések (50 pont)python3Wrong answer 2/50140ms23220 KiB
from collections import defaultdict

def elerheto(honnan, mostani):

    if mostani not in kiElerheto:
    
        kiElerheto.append(mostani)
        if len(graf[mostani]) == 2:
            if graf[mostani][0] != honnan:
                return elerheto(mostani, graf[mostani][0])
            else:
                return elerheto(mostani, graf[mostani][1])
        
        return
    else:
        return 0


beenThere = []

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:
        elerheto(i, graf[i][0])


if len(kiElerheto) == 0:

    print(0)
SubtaskSumTestVerdictTimeMemory
base2/50
1Wrong answer0/020ms11832 KiB
2Wrong answer0/0140ms20956 KiB
3Wrong answer0/220ms12280 KiB
4Wrong answer0/219ms12616 KiB
5Accepted2/219ms12956 KiB
6Wrong answer0/219ms12756 KiB
7Wrong answer0/219ms13268 KiB
8Wrong answer0/228ms13980 KiB
9Wrong answer0/237ms15032 KiB
10Wrong answer0/250ms15864 KiB
11Wrong answer0/276ms17936 KiB
12Wrong answer0/278ms18008 KiB
13Wrong answer0/327ms14300 KiB
14Wrong answer0/334ms14820 KiB
15Wrong answer0/337ms15768 KiB
16Wrong answer0/352ms16356 KiB
17Wrong answer0/367ms18564 KiB
18Wrong answer0/375ms18732 KiB
19Wrong answer0/387ms19728 KiB
20Wrong answer0/3131ms22640 KiB
21Wrong answer0/3136ms22880 KiB
22Wrong answer0/3136ms23220 KiB