41762023-03-15 19:17:12kristofElágazás nélküli úton levő települések (50 pont)python3Wrong answer 2/50140ms23316 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/020ms11924 KiB
2Wrong answer0/0138ms20892 KiB
3Wrong answer0/220ms12516 KiB
4Wrong answer0/220ms12624 KiB
5Accepted2/220ms12384 KiB
6Wrong answer0/220ms12380 KiB
7Wrong answer0/220ms12692 KiB
8Wrong answer0/230ms13468 KiB
9Wrong answer0/239ms14352 KiB
10Wrong answer0/250ms15604 KiB
11Wrong answer0/282ms17536 KiB
12Wrong answer0/276ms17676 KiB
13Wrong answer0/328ms14012 KiB
14Wrong answer0/332ms14952 KiB
15Wrong answer0/337ms15472 KiB
16Wrong answer0/352ms15752 KiB
17Wrong answer0/370ms18160 KiB
18Wrong answer0/375ms18464 KiB
19Wrong answer0/387ms19784 KiB
20Wrong answer0/3136ms22704 KiB
21Wrong answer0/3137ms23236 KiB
22Wrong answer0/3140ms23316 KiB