61902023-11-05 22:21:42jeviczkiAdószedőpython3Runtime error 0/302.086s32740 KiB
from sys import stdin
n,m,f=(int(x) for x in input().split())
utak=[[] for _ in range(n)]
for _ in range (m):
    kezd,veg=stdin.readline().split()
    kezd=int(kezd)-1
    veg=int(veg)-1
    utak[kezd].append(veg)
    utak[veg].append(kezd)
latott=[0]*n
fovaros=[f-1]
javitando=[]
while fovaros:
    for q in fovaros:
        latott[q]=2
latando=[]
for q in fovaros:
    for y in utak[q]:
        if latott[y]<2:
            javitando.append((q+1,y+1))
        if latott[y]==0:
            latott[y]=1
            latando.append(y)
fovaros=latando 
print (len(javitando))
for d in javitando:
    print (*d)

SubtaskSumTestVerdictTimeMemory
base0/30
1Runtime error0/018ms11052 KiB
2Time limit exceeded0/02.063s23740 KiB
3Time limit exceeded0/12.079s6124 KiB
4Time limit exceeded0/12.086s6472 KiB
5Time limit exceeded0/12.043s6512 KiB
6Time limit exceeded0/12.075s6588 KiB
7Time limit exceeded0/12.048s6824 KiB
8Time limit exceeded0/12.071s7096 KiB
9Time limit exceeded0/22.063s7396 KiB
10Time limit exceeded0/22.062s7764 KiB
11Time limit exceeded0/22.082s7944 KiB
12Time limit exceeded0/22.066s9112 KiB
13Time limit exceeded0/22.075s12140 KiB
14Time limit exceeded0/22.052s25036 KiB
15Time limit exceeded0/12.065s32016 KiB
16Time limit exceeded0/12.056s30676 KiB
17Time limit exceeded0/22.081s32736 KiB
18Time limit exceeded0/22.069s32672 KiB
19Time limit exceeded0/22.061s32732 KiB
20Time limit exceeded0/22.069s32716 KiB
21Time limit exceeded0/22.062s32740 KiB