Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
graph=[[] for _ in range(n)]

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

sign=[-1]*n
sign[0]=0
work=[]
work_next=graph[0]
for x in work_next:
    sign[x]=0


while work_next:
    work=work_next[:]
    work_next=[]
    for x in work:
        for y in graph[x]:
            if sign[y]>=0 : continue
            if y in work_next : continue
            sign[y]=x
            work_next.append(y)

if -1 in sign : print("No");exit()
print("Yes")
for i in range(1,n):
    print(sign[i]+1)

Fixed submission:
n,m=map(int,input().split())
graph=[[] for _ in range(n)]

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

sign=[-1]*n
sign[0]=0
work=[]
work_next=graph[0]
for x in work_next:
    sign[x]=0


while work_next:
    work=work_next[:]
    work_next=[]
    for x in work:
        for y in graph[x]:
            if sign[y]>=0 : continue
            if y in work_next : continue
            sign[y]=x
            work_next.append(y)

if -1 in sign : print("No");exit()
print("Yes")
for i in range(1,n):
    print(sign[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(m)]
con=[[] for i in range(n+1)]
check=[0 for i in range(n+1)]
for x in lst: con[x[0]].append(x[1]);con[x[1]].append(x[0])
check[1]=1
work=[1]
while check.count(0)>1:
    workc=[]
    for x in work:
        for y in con[x]:
            if check[y] : continue
            else : 
                workc.append(y)
                check[y]=x
    work=workc
print("Yes")
for j in range(2,n+1):
    print(check[j])

Fixed submission:
n,m=map(int,input().split())
graph=[[] for _ in range(n)]

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

sign=[-1]*n
sign[0]=0
work=[]
work_next=graph[0]
for x in work_next:
    sign[x]=0


while work_next:
    work=work_next[:]
    work_next=[]
    for x in work:
        for y in graph[x]:
            if sign[y]>=0 : continue
            if y in work_next : continue
            sign[y]=x
            work_next.append(y)

if -1 in sign : print("No");exit()
print("Yes")
for i in range(1,n):
    print(sign[i]+1)

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(m)]
con=[[] for i in range(n+1)]
check=[0 for i in range(n+1)]
for x in lst: con[x[0]].append(x[1]);con[x[1]].append(x[0])
check[1]=1
dis=[[1]]
i=0
while check.count(0)>1:
    work=[]
    for x in dis[i]:
        for y in con[x]:
            if check[y] : continue
            else : 
                work.append(y)
                check[y]=x
    dis.append(work)
    i+=1
print("Yes")
for j in range(2,n+1):
    print(check[j])


Fixed submission:
n,m=map(int,input().split())
graph=[[] for _ in range(n)]

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

sign=[-1]*n
sign[0]=0
work=[]
work_next=graph[0]
for x in work_next:
    sign[x]=0


while work_next:
    work=work_next[:]
    work_next=[]
    for x in work:
        for y in graph[x]:
            if sign[y]>=0 : continue
            if y in work_next : continue
            sign[y]=x
            work_next.append(y)

if -1 in sign : print("No");exit()
print("Yes")
for i in range(1,n):
    print(sign[i]+1)

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
lst=[list(map(int,input().split())) for i in range(m)]
con=[[] for i in range(m+1)]
check=[0 for i in range(n+1)]
for x in lst: con[x[0]].append(x[1]);con[x[1]].append(x[0])
check[1]=1
dis=[[1]]
i=0
while check.count(0)>1:
    work=[]
    for x in dis[i]:
        for y in con[x]:
            if check[y] : continue
            else : 
                work.append(y)
                check[y]=x
    dis.append(work)
    i+=1
print("Yes")
for j in range(2,n+1):
    print(check[j])


Fixed submission:
n,m=map(int,input().split())
graph=[[] for _ in range(n)]

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

sign=[-1]*n
sign[0]=0
work=[]
work_next=graph[0]
for x in work_next:
    sign[x]=0


while work_next:
    work=work_next[:]
    work_next=[]
    for x in work:
        for y in graph[x]:
            if sign[y]>=0 : continue
            if y in work_next : continue
            sign[y]=x
            work_next.append(y)

if -1 in sign : print("No");exit()
print("Yes")
for i in range(1,n):
    print(sign[i]+1)