Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
n,m = map(int,input().split())
 
turo = [[] for i in range(n)]
q = deque()
his = []

for i in range(m):
    a,b = map(int,input().split())
    turo[a-1].append(b-1)
    turo[b-1].append(a-1)
 
par = [i for i in range(n)]
rank = [sys.maxsize for i in range(n)]
rank[0] = 0
q.append(0)

 
while len(q) > 0:
    #print(q)
    room = q.popleft()
    if room not in his:
        his.append(0)
    else:
        continue
    for room2 in turo[room]:
        if rank[room] < rank[room2]:
            q.append(room2)
            par[room2] = room
            rank[room2] = rank[room]+1

if len(his) < n:
    print("No")
    exit()
 
print("Yes")
for i in range(1,n):
    print(par[i]+1)

Fixed submission:
from collections import deque
import sys
n,m = map(int,input().split())
 
turo = [[] for i in range(n)]
q = deque()
his = [False]*n
for i in range(m):
    a,b = map(int,input().split())
    turo[a-1].append(b-1)
    turo[b-1].append(a-1)
 
par = [i for i in range(n)]
rank = [sys.maxsize for i in range(n)]
rank[0] = 0
q.append(0)
 
while len(q) > 0:
    #print(q)
    room = q.popleft()
    
    if not his[room] :
        his[room] = True
    else:
        continue
    for room2 in turo[room]:
        if rank[room] < rank[room2]:
            q.append(room2)
            par[room2] = room
            rank[room2] = rank[room]+1
 
if len(his) < n:
    print("No")
    exit()
 
print("Yes")
for i in range(1,n):
    print(par[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m = map(int,input().split())

turo = [[] for i in range(n)]
q = deque()
his = []

def root(x):
    if par[x] == x:
        return x
    else:
        return root(par[x])

for i in range(m):
    a,b = map(int,input().split())
    turo[a-1].append(b-1)
    turo[b-1].append(a-1)

par = [i for i in range(n)]
q.append(0)
his.append(0)

while len(q) > 0:
    #print(q)
    room = q.popleft()
    #print(room+1)
    for room2 in turo[room]:
        if room2 not in his:
            his.append(room2)
            q.append(room2)
            par[room2] = room

if len(his) < n:
    print("No")
    exit()
 
print("Yes")
for i in range(1,n):
    print(par[i]+1)

Fixed submission:
from collections import deque
import sys
n,m = map(int,input().split())
 
turo = [[] for i in range(n)]
q = deque()
his = [False]*n
for i in range(m):
    a,b = map(int,input().split())
    turo[a-1].append(b-1)
    turo[b-1].append(a-1)
 
par = [i for i in range(n)]
rank = [sys.maxsize for i in range(n)]
rank[0] = 0
q.append(0)
 
while len(q) > 0:
    #print(q)
    room = q.popleft()
    
    if not his[room] :
        his[room] = True
    else:
        continue
    for room2 in turo[room]:
        if rank[room] < rank[room2]:
            q.append(room2)
            par[room2] = room
            rank[room2] = rank[room]+1
 
if len(his) < n:
    print("No")
    exit()
 
print("Yes")
for i in range(1,n):
    print(par[i]+1)

Buggy python submission (verdict: Runtime Error):
from collections import deque
n,m = map(int,input().split())

turo = [[] for i in range(n)]
q = deque()
his = []

def root(x):
    if par[x] == x:
        return x
    else:
        return root(par[x])

for i in range(m):
    a,b = map(int,input().split())
    turo[a-1].append(b-1)
    turo[b-1].append(a-1)

par = [i for i in range(n)]
q.append(0)
his.append(0)

while len(q) > 0:
    #print(q)
    room = q.popleft()
    #print(room+1)
    for room2 in turo[room]:
        if room2 not in his:
            his.append(room2)
            q.append(room2)
            par[room2] = room

#print(turo,par)
for i in range(1,n):
    if (root(i) != 0):
        print("No")
        exit()
 
print("Yes")
for i in range(1,n):
    print(par[i]+1)

Fixed submission:
from collections import deque
import sys
n,m = map(int,input().split())
 
turo = [[] for i in range(n)]
q = deque()
his = [False]*n
for i in range(m):
    a,b = map(int,input().split())
    turo[a-1].append(b-1)
    turo[b-1].append(a-1)
 
par = [i for i in range(n)]
rank = [sys.maxsize for i in range(n)]
rank[0] = 0
q.append(0)
 
while len(q) > 0:
    #print(q)
    room = q.popleft()
    
    if not his[room] :
        his[room] = True
    else:
        continue
    for room2 in turo[room]:
        if rank[room] < rank[room2]:
            q.append(room2)
            par[room2] = room
            rank[room2] = rank[room]+1
 
if len(his) < n:
    print("No")
    exit()
 
print("Yes")
for i in range(1,n):
    print(par[i]+1)

Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
par = []
rank = []
def init(n):
    for i in range(n):
        par.append(i)
        rank.append(sys.maxsize)
    rank[0] = 0
 
def root(x):
    if par[x] == x:
        return x
    else:
        return root(par[x])
        
 
def same(x,y):
    if root(x) == root(y):
        return True
    else:
        return False
 
def unite(x,y):
    #print(par[x],par[y],rank[root(x)],rank[root(y)])
    if par[x]==par[y]:
        return
    if rank[x] != sys.maxsize and rank[x] == rank[y]:
        pass
    elif(rank[x] < rank[y]):
        par[y] = x
        rank[y] = rank[x] + 1
    else:
        par[x] = y
        rank[x] = rank[y] + 1
        #if rank[x]==rank[y]:
         #   rank[x] += 1
    #print(par,rank)
 
n,m = map(int,input().split())

turo = [[] for i in range(n)]
q = deque()
his = []

for i in range(m):
    a,b = map(int,input().split())
    turo[a-1].append(b-1)
    turo[b-1].append(a-1)

init(n)
q.append(0)
his.append(0)

while len(q) > 0:
    #print(q)
    room = q.popleft()
    #print(room+1)
    for room2 in turo[room]:
        if room2 not in his:
            his.append(room2)
            q.append(room2)
            unite(room,room2)

print(turo,par)
for i in range(1,n):
    if (root(i) != 0):
        print("No")
        exit()
 
print("Yes")
for i in range(1,n):
    print(par[i]+1)

Fixed submission:
from collections import deque
import sys
n,m = map(int,input().split())
 
turo = [[] for i in range(n)]
q = deque()
his = [False]*n
for i in range(m):
    a,b = map(int,input().split())
    turo[a-1].append(b-1)
    turo[b-1].append(a-1)
 
par = [i for i in range(n)]
rank = [sys.maxsize for i in range(n)]
rank[0] = 0
q.append(0)
 
while len(q) > 0:
    #print(q)
    room = q.popleft()
    
    if not his[room] :
        his[room] = True
    else:
        continue
    for room2 in turo[room]:
        if rank[room] < rank[room2]:
            q.append(room2)
            par[room2] = room
            rank[room2] = rank[room]+1
 
if len(his) < n:
    print("No")
    exit()
 
print("Yes")
for i in range(1,n):
    print(par[i]+1)