Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M=map(int, input().split())
alist = []
blist = []
for _ in range(M):
    a,b=map(int, input().split())
    alist.append(a)
    blist.append(b)
rdic = {}
d = deque()
def find_index(n):
    returnlist = []
    for indexa,i in enumerate(alist):
        if i == n:
            returnlist.append(blist[indexa])
    for indexb,i in enumerate(blist):
        if i == n:
            returnlist.append(alist[indexb])
    return returnlist
d.append(1)
rdic[1] = 0
c = 0
while True:
    getlist = find_index(d[0])
    for i in getlist:
        if i not in rdic:
            rdic[i] = d[0]
            d.append(i)
            c+=1
    if c == N-1:
        break
    d.popleft()
print('Yes')
for n in range(2,N+1):
    print(rdic[n])

Fixed submission:
from collections import deque
N,M=map(int, input().split())
alist = []
blist = []
T = [ [] for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    T[a-1].append(b)
    T[b-1].append(a)
# T[i]にはi+1が接続してる数のリスト
rdic = [0]*(N)
d = deque()
d.append(1)
c = 0
ans = [0]*N
while len(d)>0:
    getlist = T[d[0]-1]
    for i in getlist:
        if rdic[i-1]==0:
            rdic[i-1] = d[0]
            d.append(i)
    d.popleft()
print('Yes')
for n in range(2,N+1):
    print(rdic[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M=map(int, input().split())
alist = []
blist = []
for _ in range(M):
    a,b=map(int, input().split())
    alist.append(a)
    blist.append(b)
rdic = {}
d = deque()
def find_index(n):
    returnlist = []
    for indexa,i in enumerate(alist):
        if i == n:
            returnlist.append(blist[indexa])
    for indexb,i in enumerate(blist):
        if i == n:
            returnlist.append(alist[indexb])
    return returnlist
d.append(1)
rdic[1] = 0
while len(rdic)!=N:
    getlist = find_index(d[0])
    for i in getlist:
        if i not in rdic:
            rdic[i] = d[0]
            d.append(i)
    d.popleft()
print('Yes')
for n in range(2,N+1):
    print(rdic[n])

Fixed submission:
from collections import deque
N,M=map(int, input().split())
alist = []
blist = []
T = [ [] for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    T[a-1].append(b)
    T[b-1].append(a)
# T[i]にはi+1が接続してる数のリスト
rdic = [0]*(N)
d = deque()
d.append(1)
c = 0
ans = [0]*N
while len(d)>0:
    getlist = T[d[0]-1]
    for i in getlist:
        if rdic[i-1]==0:
            rdic[i-1] = d[0]
            d.append(i)
    d.popleft()
print('Yes')
for n in range(2,N+1):
    print(rdic[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
alist = []
blist = []
ablist = []
N,M=map(int, input().split())
for _ in range(M):
    a,b=map(int, input().split())
    alist.append(a)
    blist.append(b)
Ndic = {1:[0,0]}
def duplistindex(list1,list2, number):
    returnlist = []
    for l in [i for i, x in enumerate(list1) if x == number]:
        returnlist.append(list2[l])
    for l in [i for i, x in enumerate(list2) if x == number]:
        returnlist.append(list1[l])
    return returnlist
reviewed = [1]
while reviewed:
    for review in reviewed:
        for i in duplistindex(alist,blist,review):
            if i not in Ndic.keys():
                Ndic[i] = []
                Ndic[i].append(Ndic[review][0] + 1)
                Ndic[i].append(review)
                reviewed.append(i)
            else:
                if Ndic[i][0] > Ndic[review][0] + 1:
                    Ndic[i][0] = Ndic[review][0] + 1
                    Ndic[i][1] = review
                    reviewed.append(i)
        reviewed.remove(review)
print('Yes')
for i in range(N-1):
    print(Ndic[i+2][1])

Fixed submission:
from collections import deque
N,M=map(int, input().split())
alist = []
blist = []
T = [ [] for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    T[a-1].append(b)
    T[b-1].append(a)
# T[i]にはi+1が接続してる数のリスト
rdic = [0]*(N)
d = deque()
d.append(1)
c = 0
ans = [0]*N
while len(d)>0:
    getlist = T[d[0]-1]
    for i in getlist:
        if rdic[i-1]==0:
            rdic[i-1] = d[0]
            d.append(i)
    d.popleft()
print('Yes')
for n in range(2,N+1):
    print(rdic[n-1])

Buggy python submission (verdict: Time Limit Exceeded):
alist = []
blist = []
ablist = []
N,M=map(int, input().split())
for _ in range(M):
    a,b=map(int, input().split())
    alist.append(a)
    blist.append(b)
Ndic = {1:[0,0]}
def duplistindex(list1,list2, number):
    returnlist = []
    for l in [i for i, x in enumerate(list1) if x == number]:
        returnlist.append(list2[l])
    for l in [i for i, x in enumerate(list2) if x == number]:
        returnlist.append(list1[l])
    return returnlist
reviewed = [1]
while reviewed:
    for review in reviewed:
        for i in duplistindex(alist,blist,review):
            if i not in Ndic.keys():
                Ndic[i] = []
                Ndic[i].append(Ndic[review][0] + 1)
                Ndic[i].append(review)
                reviewed.append(i)
            else:
                if Ndic[i][0] > Ndic[review][0] + 1:
                    Ndic[i][0] = Ndic[review][0] + 1
                    Ndic[i][1] = review
                    reviewed.append(i)
        reviewed.remove(review)
print('Yes')
for i in range(N-1):
    print(Ndic[i+2][1])

Fixed submission:
from collections import deque
N,M=map(int, input().split())
alist = []
blist = []
T = [ [] for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    T[a-1].append(b)
    T[b-1].append(a)
# T[i]にはi+1が接続してる数のリスト
rdic = [0]*(N)
d = deque()
d.append(1)
c = 0
ans = [0]*N
while len(d)>0:
    getlist = T[d[0]-1]
    for i in getlist:
        if rdic[i-1]==0:
            rdic[i-1] = d[0]
            d.append(i)
    d.popleft()
print('Yes')
for n in range(2,N+1):
    print(rdic[n-1])