Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
AB = []
ans = [0] * (n-1)

for i in range(m):
    AB.append(sorted(map(int,input().split())))
    
AB = sorted(AB)
    
import collections
que = collections.deque()
que.append(1)
    
while que:
    x = que.popleft()
    
    for i in AB:
        a = i[0]
        b = i[1]
        
        if x < a:
            break
        
        if a == x:
            if ans[b-2] == 0:
                ans[b-2] = x
                que.append(b)
        elif b == x:
            if ans[a-2] == 0:
                ans[a-2] = x
                que.append(a)
            
if 0 in ans:
    print("No")
else:
    print("Yes")
    
    for i in ans:
        print(i)

Fixed submission:
n,m = map(int,input().split())
ans = [-1] * n
edge = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
    
import collections
que = collections.deque()
que.append(0)
    
while que:
    x = que.popleft()
    
    for to in edge[x]:
        if ans[to] == -1:
            ans[to] = x + 1
            que.append(to)
            
if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    print(*ans[1:],sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
AB = []
ans = [0] * (n-1)

for i in range(m):
    AB.append(list(map(int,input().split())))
    
import collections
que = collections.deque()
que.append(1)
    
while que:
    x = que.popleft()
    
    for i in AB:
        a = i[0]
        b = i[1]
        
        if a == x and ans[b-2] == 0:
            ans[b-2] = x
            que.append(b)
        elif b == x and ans[a-2] == 0:
            ans[a-2] = x
            que.append(a)
            
if 0 in ans:
    print("No")
else:
    print("Yes")
    
    for i in ans:
        print(i)

Fixed submission:
n,m = map(int,input().split())
ans = [-1] * n
edge = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
    
import collections
que = collections.deque()
que.append(0)
    
while que:
    x = que.popleft()
    
    for to in edge[x]:
        if ans[to] == -1:
            ans[to] = x + 1
            que.append(to)
            
if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    print(*ans[1:],sep="\n")

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
AB = []
ans = [0] * (n-1)

for i in range(m):
    AB.append(list(map(int,input().split())))
    
import collections
que = collections.deque()
que.append(1)
    
while que:
    x = que.popleft()
    
    for i in AB:
        a = i[0]
        b = i[1]
        
        if a == x and ans[b-2] == 0:
            ans[b-2] = x
            que.append(b)
        elif b == x and ans[a-2] == 0:
            ans[a-2] = x
            que.append(a)
            
if 0 in ans:
    print("No")
else:
    print("Yes")
    
    for i in ans:
        print(i)

Fixed submission:
n,m = map(int,input().split())
ans = [-1] * n
edge = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
    
import collections
que = collections.deque()
que.append(0)
    
while que:
    x = que.popleft()
    
    for to in edge[x]:
        if ans[to] == -1:
            ans[to] = x + 1
            que.append(to)
            
if -1 in ans[1:]:
    print("No")
else:
    print("Yes")
    print(*ans[1:],sep="\n")