Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N,M = map(int, input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    
parent = [0]*(N+1)
parent[0] = -1
parent[1] = -1

nextroom = deque()
nextroom.append(1)
for j in range(N):
    for i in range(M):
        if A[i]==nextroom[0] and parent[B[i]]==0:
            nextroom.append(B[i])
            parent[B[i]] = A[i]
        if B[i]==nextroom[0] and parent[A[i]]==0:
            nextroom.append(A[i])
            parent[A[i]] = B[i]
    nextroom.popleft()
    
if parent.count(0)==0:
    print('Yes')
    for i in range(2,len(parent)):
        print(parent[i])
else:
    print('No')

Fixed submission:
from collections import deque

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

AB = [list(map(int, input().split())) for _ in range(M)]

G = {i:[] for i in range(N+1)}
for a,b in AB:
    G[a].append(b)
    G[b].append(a)
    
parent = [0]*(N+1)
parent[0]==-1
parent[1]==-1
q = deque()
q.append(1)
while len(q)>0:
    room = q.popleft()
    child = G[room]
    
    for i in child:
        if parent[i] == 0:
            parent[i] = room
            q.append(i)
    
    
if min(parent[2:])==0:
    print('No')
else:
    print('Yes')
    for i in parent[2:]:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    
parent = [0]*(N+1)
parent[0] = -1
parent[1] = -1

nextroom = [1]
for j in range(N):
    for i in range(M):
        if A[i]==nextroom[0] and parent[B[i]]==0:
            nextroom.append(B[i])
            parent[B[i]] = A[i]
        if B[i]==nextroom[0] and parent[A[i]]==0:
            nextroom.append(A[i])
            parent[A[i]] = B[i]
    nextroom.pop(0)
    
if parent.count(0)==0:
    print('Yes')
    for i in range(2,len(parent)):
        print(parent[i])
else:
    print('No')

Fixed submission:
from collections import deque

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

AB = [list(map(int, input().split())) for _ in range(M)]

G = {i:[] for i in range(N+1)}
for a,b in AB:
    G[a].append(b)
    G[b].append(a)
    
parent = [0]*(N+1)
parent[0]==-1
parent[1]==-1
q = deque()
q.append(1)
while len(q)>0:
    room = q.popleft()
    child = G[room]
    
    for i in child:
        if parent[i] == 0:
            parent[i] = room
            q.append(i)
    
    
if min(parent[2:])==0:
    print('No')
else:
    print('Yes')
    for i in parent[2:]:
        print(i)

Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    
parent = [0]*(N+1)
parent[0] = -1
parent[1] = -1

nextroom = [1]
for i in range(N):
    for i in range(M):
        if A[i]==nextroom[0] and parent[B[i]]==0:
            nextroom.append(B[i])
            parent[B[i]] = A[i]
        if B[i]==nextroom[0] and parent[A[i]]==0:
            nextroom.append(A[i])
            parent[A[i]] = B[i]
    nextroom.pop(0)
    
if parent.count(0)==0:
    print('Yes')
    for i in range(2,len(parent)):
        print(parent[i])
else:
    print('No')

Fixed submission:
from collections import deque

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

AB = [list(map(int, input().split())) for _ in range(M)]

G = {i:[] for i in range(N+1)}
for a,b in AB:
    G[a].append(b)
    G[b].append(a)
    
parent = [0]*(N+1)
parent[0]==-1
parent[1]==-1
q = deque()
q.append(1)
while len(q)>0:
    room = q.popleft()
    child = G[room]
    
    for i in child:
        if parent[i] == 0:
            parent[i] = room
            q.append(i)
    
    
if min(parent[2:])==0:
    print('No')
else:
    print('Yes')
    for i in parent[2:]:
        print(i)