183042025-10-18 20:16:14Zoli9Adószedőpython3Runtime error 19/30806ms32000 KiB
seged = list(map(int, input().split()))
n = seged[0]
m = seged[1]
fo = seged[2]
elek = []
for i in range(n+1):
    elek.append([])
for u in range(m):
    a = list(map(int, input().split()))
    elek[a[0]].append(a[1])
    elek[a[1]].append(a[0])
sor = [fo]
szintek = [-1]*(n+1)
szintek[fo] = 0
megoldas = []
count = 0
while len(sor)>0:
    aktualis = sor.pop(0)
    for i in elek[aktualis]:
        if(szintek[i] == -1):
            sor.append(i)
            szintek[i] = (szintek[aktualis]+1)
        if (szintek[i] -1 )== szintek[aktualis]:
            megoldas.append([aktualis, i])
            count += 1
print(count)
for i in range(len(megoldas)):
    print(megoldas[i][0], megoldas[i][1])

            
SubtaskSumTestVerdictTimeMemory
base19/30
1Runtime error0/016ms3124 KiB
2Runtime error0/0654ms32000 KiB
3Accepted1/117ms3128 KiB
4Accepted1/117ms3016 KiB
5Accepted1/117ms3116 KiB
6Accepted1/117ms3192 KiB
7Accepted1/116ms3332 KiB
8Accepted1/117ms3124 KiB
9Accepted2/219ms3380 KiB
10Accepted2/225ms3524 KiB
11Accepted2/224ms3636 KiB
12Accepted2/278ms5940 KiB
13Accepted2/2168ms10220 KiB
14Accepted2/2686ms31828 KiB
15Runtime error0/1611ms32000 KiB
16Accepted1/1806ms32000 KiB
17Runtime error0/2694ms32000 KiB
18Runtime error0/2669ms32000 KiB
19Runtime error0/2638ms32000 KiB
20Runtime error0/2654ms32000 KiB
21Runtime error0/2629ms32000 KiB