Buggy python submission (verdict: Time Limit Exceeded):
import math, sys
N , M = list(map(int, input().split()))

Es = [[] for _ in range(N)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A-1].append(B-1)
    Es[B-1].append(A-1)


i = 1
j = 1
d = 0
#ans = [-1 for _ in range(N)]
cand = []
used = [False for i in range(N)]
dis = [math.inf for i in range(N)]
ans = [-1 for i in range(N)]
tar = 0
cnt = 1
print("Yes")
p = 0

cand = [0]
while len(cand)>0:
    tar = cand.pop(0)
    for each in Es[tar]:
        if not used[each]:
            cand.append(each)
            ans[each]=tar+1
            used[each]= True
for i in range(1,N):
    print(ans[i])


Fixed submission:
import math, sys
from collections import deque
N , M = list(map(int, input().split()))

Es = [[] for _ in range(N+1)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A].append(B)
    Es[B].append(A)

used = [False]*(N+1)
used[1] = True

ans = [-1]*(N+1)

cand = deque([1])
while len(cand)>0:
    tar = cand.popleft()
    for each in Es[tar]:
        if used[each]:
            continue
        cand.append(each)
        ans[each]=tar
        used[each]= True

print("Yes")
for i in range(2,N+1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import math, sys
N , M = list(map(int, input().split()))

Es = [[] for _ in range(N)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A-1].append(B-1)
    Es[B-1].append(A-1)


i = 1
j = 1
dis = 0
#ans = [-1 for _ in range(N)]
cand = []
used = [-1 for i in range(N)]
used[0] = 0
tar = 0
cnt = 1
print("Yes")
p = 0
while True:
    for each in Es[tar]:
        if used[each] <0 :
            used[each] = tar
            cand.append(each)
            cnt += 1
    if len(cand) == 0:
        break
    if cnt == N:
        break
    tar = cand.pop(0)

for i in range(1,N):
    print(used[i]+1)


Fixed submission:
import math, sys
from collections import deque
N , M = list(map(int, input().split()))

Es = [[] for _ in range(N+1)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A].append(B)
    Es[B].append(A)

used = [False]*(N+1)
used[1] = True

ans = [-1]*(N+1)

cand = deque([1])
while len(cand)>0:
    tar = cand.popleft()
    for each in Es[tar]:
        if used[each]:
            continue
        cand.append(each)
        ans[each]=tar
        used[each]= True

print("Yes")
for i in range(2,N+1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import math, sys
N , M = list(map(int, input().split()))

Es = [[] for _ in range(N)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A-1].append(B-1)
    Es[B-1].append(A-1)


i = 1
j = 1
dis = 0
ans = [-1 for _ in range(N)]
cand = []
used = [False for i in range(N)]
used[0] = True
tar = 0
cnt = 1
while True:
    for each in Es[tar]:
        if not used[each]:
            used[each]= True
            ans[each] = tar
            cand.append(each)
            cnt += 1
    if len(cand) == 0:
        break
    if cnt == N:
        break
    tar = cand.pop(0)

print("Yes")
for i in range(1,N):
    print(ans[i]+1)

Fixed submission:
import math, sys
from collections import deque
N , M = list(map(int, input().split()))

Es = [[] for _ in range(N+1)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A].append(B)
    Es[B].append(A)

used = [False]*(N+1)
used[1] = True

ans = [-1]*(N+1)

cand = deque([1])
while len(cand)>0:
    tar = cand.popleft()
    for each in Es[tar]:
        if used[each]:
            continue
        cand.append(each)
        ans[each]=tar
        used[each]= True

print("Yes")
for i in range(2,N+1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import math, sys
N , M = list(map(int, input().split()))

Es = [[] for _ in range(N)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A-1].append(B-1)
    Es[B-1].append(A-1)


i = 1
j = 1
dis = 0
ans = [-1 for _ in range(N)]
cand = []
used = [False for i in range(N)]
used[0] = True
tar = 0

while True:
    for each in Es[tar]:
        if not used[each]:
            used[each]= True
            ans[each] = tar
            cand.append(each)
    if len(cand) == 0:
        break
    else:
        tar = cand.pop(0)

print("Yes")
for i in range(1,N):
    print(ans[i]+1)

Fixed submission:
import math, sys
from collections import deque
N , M = list(map(int, input().split()))

Es = [[] for _ in range(N+1)]
for i in range(M):
    A , B = list(map(int, input().split()))
    Es[A].append(B)
    Es[B].append(A)

used = [False]*(N+1)
used[1] = True

ans = [-1]*(N+1)

cand = deque([1])
while len(cand)>0:
    tar = cand.popleft()
    for each in Es[tar]:
        if used[each]:
            continue
        cand.append(each)
        ans[each]=tar
        used[each]= True

print("Yes")
for i in range(2,N+1):
    print(ans[i])