Buggy python submission (verdict: Time Limit Exceeded):
import queue
n,m = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b)
    graph[b-1].append(a)
ans = [0]* n
flag = [0]*n
q = queue.deque()
q.append(1)
while q:
    tmp = q.popleft()
    flag[tmp-1] = 1
    for i in graph[tmp-1]:
        if flag[i-1] == 0:
            q.append(i)
            if ans[i-1] == 0:
                ans[i-1] = tmp
if sum(flag) == n:
    print('Yes')
    for i in range(1,n):
        print(ans[i])
        
else:
    print('No')

Fixed submission:
import queue
n,m = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b)
    graph[b-1].append(a)
ans = [0]* n
q = queue.deque()
q.append(1)
while q:
    tmp = q.popleft()
    for i in graph[tmp-1]:
        if ans[i-1] == 0:
            q.append(i)
            ans[i-1] = tmp
                
if 0 in ans:
    print('No')
        
else:
    print('Yes')
    for i in range(1,n):
        print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import queue
n,m = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b)
    graph[b-1].append(a)
ans = [0]* n
flag = [0]*n
q = queue.deque()
q.append(1)
while q:
    tmp = q.popleft()
    flag[tmp-1] = 1
    for i in graph[tmp-1]:
        if flag[i-1] == 0:
            q.append(i)
            if ans[i-1] == 0:
                ans[i-1] = tmp
if sum(flag) == n:
    print('Yes')
    for i in range(1,n):
        print(ans[i])
        
else:
    print('No')

Fixed submission:
import queue
n,m = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b)
    graph[b-1].append(a)
ans = [0]* n
q = queue.deque()
q.append(1)
while q:
    tmp = q.popleft()
    for i in graph[tmp-1]:
        if ans[i-1] == 0:
            q.append(i)
            ans[i-1] = tmp
                
if 0 in ans:
    print('No')
        
else:
    print('Yes')
    for i in range(1,n):
        print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
import queue
n,m = map(int,input().split())
graph = [[0 for i in range(n)]for j in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1][b-1] = 1
    graph[b-1][a-1] = 1
ans = [0]* n
flag = [0]*n
q = queue.deque()
q.append(1)
while q:
    tmp = q.popleft()
    flag[tmp-1] = 1
    for i in range(len(graph[tmp-1])):
        if graph[tmp-1][i] == 1:
            if flag[i] == 0:
                q.append(i+1)
                if ans[i] == 0:
                    ans[i] = tmp
if sum(flag) == n:
    print('Yes')
    for i in range(1,n):
        print(ans[i])
        
else:
    print('No')

Fixed submission:
import queue
n,m = map(int,input().split())
graph = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    graph[a-1].append(b)
    graph[b-1].append(a)
ans = [0]* n
q = queue.deque()
q.append(1)
while q:
    tmp = q.popleft()
    for i in graph[tmp-1]:
        if ans[i-1] == 0:
            q.append(i)
            ans[i-1] = tmp
                
if 0 in ans:
    print('No')
        
else:
    print('Yes')
    for i in range(1,n):
        print(ans[i])