Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,m = map(int, input().split())
ab=deque()
for _ in range(m):
    ab.append(list(map(int, input().split())))

ans=deque([0]+[1]+[0]*(n-1))
tmp=deque()

tansakuheya=deque([1])

for _ in range(100009):

	for heya in tansakuheya:

		for gyou in range(m):
			if ab[gyou][0]==heya:
				if ans[ab[gyou][1]]==0:
					ans[ab[gyou][1]]=ab[gyou][0]
					tmp.append(ab[gyou][1])

			if ab[gyou][1]==heya:
				if ans[ab[gyou][0]]==0:
					ans[ab[gyou][0]]=ab[gyou][1]
					tmp.append(ab[gyou][0])
	
	if len(tmp)==0:
		break

	tansakuheya=tmp
	tmp=deque()

print("Yes")
for i in range(2,n+1):
	print(ans[i])

Fixed submission:
from collections import deque
n,m = map(int, input().split())
ikisaki=[[] for _ in range(n+1)]

for _ in range(m):
    a,b = map(int, input().split())
    ikisaki[a].append(b)
    ikisaki[b].append(a)
ans=[0]+[1]+[0]*(n-1)
tansakuheya=deque([1])
tmp=deque()

for _ in range(1000009):

    for bangou in tansakuheya:

        for heya in ikisaki[bangou]:
            if ans[heya]==0:
                ans[heya]=bangou
                tmp.append(heya)

    tansakuheya=tmp.copy()
    tmp=deque()


    if not tansakuheya:
        break

print("Yes")
for i in range(2,n+1):
	print(ans[i])

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

ans=[0]+[1]+[0]*(n-1)
tmp=[]

tansakuheya=[1]

while len(tansakuheya)>0:

	for heya in tansakuheya:

		for gyou in range(m):
			if ab[gyou][0]==heya:
				if ans[ab[gyou][1]]==0:
					ans[ab[gyou][1]]=ab[gyou][0]
					tmp.append(ab[gyou][1])

			if ab[gyou][1]==heya:
				if ans[ab[gyou][0]]==0:
					ans[ab[gyou][0]]=ab[gyou][1]
					tmp.append(ab[gyou][0])

	tansakuheya=tmp
	tmp=[]

print("Yes")
for i in range(2,n+1):
	print(ans[i])

Fixed submission:
from collections import deque
n,m = map(int, input().split())
ikisaki=[[] for _ in range(n+1)]

for _ in range(m):
    a,b = map(int, input().split())
    ikisaki[a].append(b)
    ikisaki[b].append(a)
ans=[0]+[1]+[0]*(n-1)
tansakuheya=deque([1])
tmp=deque()

for _ in range(1000009):

    for bangou in tansakuheya:

        for heya in ikisaki[bangou]:
            if ans[heya]==0:
                ans[heya]=bangou
                tmp.append(heya)

    tansakuheya=tmp.copy()
    tmp=deque()


    if not tansakuheya:
        break

print("Yes")
for i in range(2,n+1):
	print(ans[i])

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

ans=[0]+[1]+[0]*(n-1)
tmp=[]

tansakuheya=[1]

while len(tansakuheya)>0:

	for heya in tansakuheya:

		for gyou in range(m):
			if ab[gyou][0]==heya:
				if ans[ab[gyou][1]]==0:
					ans[ab[gyou][1]]=ab[gyou][0]
					tmp.append(ab[gyou][1])

			if ab[gyou][1]==heya:
				if ans[ab[gyou][0]]==0:
					ans[ab[gyou][0]]=ab[gyou][1]
					tmp.append(ab[gyou][0])

	tansakuheya=tmp
	tmp=[]

print("Yes")
for i in range(2,n+1):
	print(ans[i])

Fixed submission:
from collections import deque
n,m = map(int, input().split())
ikisaki=[[] for _ in range(n+1)]

for _ in range(m):
    a,b = map(int, input().split())
    ikisaki[a].append(b)
    ikisaki[b].append(a)
ans=[0]+[1]+[0]*(n-1)
tansakuheya=deque([1])
tmp=deque()

for _ in range(1000009):

    for bangou in tansakuheya:

        for heya in ikisaki[bangou]:
            if ans[heya]==0:
                ans[heya]=bangou
                tmp.append(heya)

    tansakuheya=tmp.copy()
    tmp=deque()


    if not tansakuheya:
        break

print("Yes")
for i in range(2,n+1):
	print(ans[i])