Submission #13351843


Source Code Expand

Copy
import sys
from collections import deque

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())

G = [[] for _ in range(N + 1)]
m = map(int, read().split())
for a, b in zip(m, m):
    G[a].append(b)
    G[b].append(a)

par = [0] * (N + 1)
visited = [0] * (N + 1)
root = 1
visited[root] = 1
q = deque([root])
while q:
    v = q.popleft()
    for w in G[v]:
        if visited[w]:
            continue
        visited[w] = 1
        par[w] = v
        q.append(w)

print('Yes')
print(*par[2:], sep='\n')

Submission Info

Submission Time
Task D - .. (Double Dots)
User maspy
Language Python (3.8.2)
Score 400
Code Size 621 Byte
Status
Exec Time 440 ms
Memory 54756 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt
Subtask1 400 / 400 sample_01.txt, sample_02.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt, sub1_22.txt, sub1_23.txt, sub1_24.txt, sub1_25.txt, sub1_26.txt, sub1_27.txt, sub1_28.txt, sub1_29.txt, sub1_30.txt, sub1_31.txt, sub1_32.txt, sub1_33.txt, sub1_34.txt, sub1_35.txt, sub1_36.txt, sub1_37.txt
Case Name Status Exec Time Memory
sample_01.txt 19 ms 9412 KB
sample_02.txt 20 ms 9256 KB
sub1_01.txt 145 ms 25836 KB
sub1_02.txt 115 ms 21840 KB
sub1_03.txt 252 ms 36540 KB
sub1_04.txt 207 ms 32244 KB
sub1_05.txt 31 ms 11036 KB
sub1_06.txt 151 ms 26084 KB
sub1_07.txt 62 ms 15676 KB
sub1_08.txt 235 ms 31776 KB
sub1_09.txt 276 ms 38656 KB
sub1_10.txt 278 ms 38720 KB
sub1_11.txt 279 ms 38584 KB
sub1_12.txt 209 ms 30320 KB
sub1_13.txt 281 ms 38556 KB
sub1_14.txt 272 ms 38492 KB
sub1_15.txt 238 ms 32068 KB
sub1_16.txt 307 ms 51224 KB
sub1_17.txt 172 ms 29468 KB
sub1_18.txt 295 ms 39116 KB
sub1_19.txt 202 ms 31464 KB
sub1_20.txt 50 ms 15968 KB
sub1_21.txt 377 ms 47720 KB
sub1_22.txt 189 ms 40376 KB
sub1_23.txt 92 ms 23828 KB
sub1_24.txt 381 ms 46096 KB
sub1_25.txt 440 ms 53716 KB
sub1_26.txt 326 ms 41536 KB
sub1_27.txt 391 ms 47588 KB
sub1_28.txt 426 ms 51576 KB
sub1_29.txt 23 ms 9684 KB
sub1_30.txt 198 ms 43356 KB
sub1_31.txt 348 ms 47128 KB
sub1_32.txt 329 ms 44296 KB
sub1_33.txt 357 ms 47124 KB
sub1_34.txt 192 ms 42796 KB
sub1_35.txt 199 ms 42524 KB
sub1_36.txt 371 ms 54756 KB
sub1_37.txt 23 ms 9456 KB