Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]
A = [ [0 for __ in range(N)] for _ in range(N)]
for path in P:
    A[path[1]-1][path[0]-1]=1
    A[path[0]-1][path[1]-1]=1
#print(A)
depth_list = [0 for _ in range(N)]
next_generation = set([0])
depth = 0
#old_generation = set()
direction = [0 for _ in range(N)]
used = [0 for _ in range(N)]
while len(next_generation)!=0:
    #print('next_gen',next_generation)
    current = next_generation
    for node in next_generation:
        used[node] = 1
    #[old_generation.add(node) for node in next_generation]
    next_generation = set()
    for index in current:
        depth_list[index]=depth
    for node in current:
        #print('node',node,':',A[node])
        
        #print('old',old_generation)
        for i,neighbor in enumerate(A[node]):
            #print("trm",neighbor)

            if neighbor == 1 and used[i]==0:
                #print("unseen",i)
                next_generation.add(i)
                direction[i]=node+1
    depth+=1
if used.count(1) != N:
    print('No')
else:
    print('Yes')
    for d in direction[1:]:
        print(d)
#print(depth_list)
        

Fixed submission:
from collections import deque
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]
A = [ [] for _ in range(N)]
#node_info = [{'node':d,'connect':[],'depth':-1,'dir':-1} for d in range(N)]

for path in P:
    A[path[1]-1].append(path[0]-1)
    A[path[0]-1].append(path[1]-1)
#print(A)

previous = [-1 for i in range(N)]
previous[0]=0

que = deque([0])

while len(que) != 0:
    v = que.popleft()
    for v_i in A[v]:
        if previous[v_i] != -1:
            continue
        else:
            que.append(v_i)
            previous[v_i] = v
for i in range(N):
    if previous[i] == -1:
        print('No')
        exit()
print('Yes')
for i in range(1,N):
    print(previous[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]
A = [ [0 for __ in range(N)] for _ in range(N)]
for path in P:
    A[path[1]-1][path[0]-1]=1
    A[path[0]-1][path[1]-1]=1
#print(A)
depth_list = [0 for _ in range(N)]
next_generation = set([0])
depth = 0
#old_generation = set()
direction = [0 for _ in range(N)]
used = [0 for _ in range(N)]
while len(next_generation)!=0:
    #print('next_gen',next_generation)
    current = next_generation
    for node in next_generation:
        used[node] = 1
    #[old_generation.add(node) for node in next_generation]
    next_generation = set()
    for index in current:
        depth_list[index]=depth
    for node in current:
        #print('node',node,':',A[node])
        
        #print('old',old_generation)
        for i,neighbor in enumerate(A[node]):
            #print("trm",neighbor)

            if neighbor == 1 and used[i]==0:
                #print("unseen",i)
                next_generation.add(i)
                direction[i]=node+1
    depth+=1
if used.count(1) != N:
    print('No')
else:
    print('Yes')
    for d in direction[1:]:
        print(d)
#print(depth_list)
        

Fixed submission:
from collections import deque
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]
A = [ [] for _ in range(N)]
#node_info = [{'node':d,'connect':[],'depth':-1,'dir':-1} for d in range(N)]

for path in P:
    A[path[1]-1].append(path[0]-1)
    A[path[0]-1].append(path[1]-1)
#print(A)

previous = [-1 for i in range(N)]
previous[0]=0

que = deque([0])

while len(que) != 0:
    v = que.popleft()
    for v_i in A[v]:
        if previous[v_i] != -1:
            continue
        else:
            que.append(v_i)
            previous[v_i] = v
for i in range(N):
    if previous[i] == -1:
        print('No')
        exit()
print('Yes')
for i in range(1,N):
    print(previous[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]
A = [ [0 for __ in range(N)] for _ in range(N)]
for path in P:
    A[path[1]-1][path[0]-1]=1
    A[path[0]-1][path[1]-1]=1
#print(A)
depth_list = [0 for _ in range(N)]
next_generation = set([0])
depth = 0
old_generation = set()
direction = [0 for _ in range(N)]
while len(next_generation)!=0:
    #print('next_gen',next_generation)
    current = next_generation
    [old_generation.add(node) for node in next_generation]
    next_generation = set()
    for index in current:
        depth_list[index]=depth
    for node in current:
        #print('node',node,':',A[node])
        
        #print('old',old_generation)
        for i,neighbor in enumerate(A[node]):
            #print("trm",neighbor)

            if neighbor == 1 and i not in old_generation:
                #print("unseen",i)
                next_generation.add(i)
                direction[i]=node+1
    depth+=1
if len(old_generation) != N:
    print('No')
else:
    print('Yes')
    for d in direction[1:]:
        print(d)
#print(depth_list)
        

Fixed submission:
from collections import deque
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]
A = [ [] for _ in range(N)]
#node_info = [{'node':d,'connect':[],'depth':-1,'dir':-1} for d in range(N)]

for path in P:
    A[path[1]-1].append(path[0]-1)
    A[path[0]-1].append(path[1]-1)
#print(A)

previous = [-1 for i in range(N)]
previous[0]=0

que = deque([0])

while len(que) != 0:
    v = que.popleft()
    for v_i in A[v]:
        if previous[v_i] != -1:
            continue
        else:
            que.append(v_i)
            previous[v_i] = v
for i in range(N):
    if previous[i] == -1:
        print('No')
        exit()
print('Yes')
for i in range(1,N):
    print(previous[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]
A = [ [0 for __ in range(N)] for _ in range(N)]
for path in P:
    A[path[1]-1][path[0]-1]=1
    A[path[0]-1][path[1]-1]=1
#print(A)
depth_list = [0 for _ in range(N)]
next_generation = set([0])
depth = 0
old_generation = set()
while len(next_generation)!=0:
    #print('next_gen',next_generation)
    current = next_generation
    [old_generation.add(node) for node in next_generation]
    next_generation = set()
    for index in current:
        depth_list[index]=depth
    for node in current:
        #print('node',node,':',A[node])
        
        #print('old',old_generation)
        for i,neighbor in enumerate(A[node]):
            #print("trm",neighbor)

            if neighbor == 1 and i not in old_generation:
                #print("unseen",i)
                next_generation.add(i)
    depth+=1
if len(old_generation) != N:
    print('No')
else:
    print('Yes')
    for node in range(1,N):
        neighbors = A[node]
        for i,neighbor in enumerate(neighbors):
            if neighbor == 1 and depth_list[i]<depth_list[node]:
                print(i+1)
                break
#print(depth_list)
        

Fixed submission:
from collections import deque
N, M = map(int,input().split()) 
P = [list(map(int,input().split())) for i in range(M)]
A = [ [] for _ in range(N)]
#node_info = [{'node':d,'connect':[],'depth':-1,'dir':-1} for d in range(N)]

for path in P:
    A[path[1]-1].append(path[0]-1)
    A[path[0]-1].append(path[1]-1)
#print(A)

previous = [-1 for i in range(N)]
previous[0]=0

que = deque([0])

while len(que) != 0:
    v = que.popleft()
    for v_i in A[v]:
        if previous[v_i] != -1:
            continue
        else:
            que.append(v_i)
            previous[v_i] = v
for i in range(N):
    if previous[i] == -1:
        print('No')
        exit()
print('Yes')
for i in range(1,N):
    print(previous[i]+1)