61932023-11-06 14:10:01dfehervariAdószedőpython3Runtime error 16/30331ms68860 KiB
from sys import stdin

def main():
    N, M, F = (int(x) for x in input().split())
    hova = [[] for _ in range(N)]
    for _ in range(M):
        A, B = stdin.readline().split()
        A = int(A) - 1; B = int(B) - 1
        hova[A].append(B)
        hova[B].append(A)
    jart = [0] * N
    szint = [F - 1]
    er = []
    while szint:
        for cs in szint:
            jart[cs] = 2
        szint2 = []
        for cs in szint:
            for cs2 in hova[cs]:
                if jart[cs2] < 2:
                    er.append((cs + 1, cs2 + 1))
                if jart[cs2] == 0:
                    jart[cs2] = 1
                    szint2.append(cs2)
        szint = szint2
    print(len(er))
    for e in er:
        print(*e)


main()
SubtaskSumTestVerdictTimeMemory
base16/30
1Runtime error0/017ms10864 KiB
2Runtime error0/0331ms68860 KiB
3Accepted1/118ms11696 KiB
4Accepted1/118ms11916 KiB
5Accepted1/118ms12024 KiB
6Accepted1/118ms12364 KiB
7Accepted1/117ms12400 KiB
8Accepted1/118ms12536 KiB
9Accepted2/220ms13592 KiB
10Accepted2/224ms13868 KiB
11Accepted2/224ms14020 KiB
12Accepted2/254ms19312 KiB
13Accepted2/2107ms28880 KiB
14Runtime error0/2291ms66888 KiB
15Runtime error0/1301ms66852 KiB
16Runtime error0/1300ms66680 KiB
17Runtime error0/2317ms66628 KiB
18Runtime error0/2298ms66584 KiB
19Runtime error0/2308ms66452 KiB
20Runtime error0/2331ms66472 KiB
21Runtime error0/2310ms66452 KiB