Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N,M = map(int,input().split())

r = [[] for i in range(N+1)]

for i in range(M):
    a,b = map(int,input().split())
    r[a].append(b)
    r[b].append(a)

miteru = deque([1])
mita = {1}
res = [-1]*(N+1)

while  miteru: 
    now = miteru.popleft()
    x =set( r[now])
    x = x - mita
    for i in x:
        miteru.append(i)
        if res[i] == -1:res[i] =now
    mita.add(now)
    
print("Yes")
for i in res[2:]:
    print(i)
#print("\n".join(res))


Fixed submission:
from collections import deque
N,M = map(int,input().split())

root = [set()for i in range(N+1)]
ans = [0 for i in range(N+1)]

for i in range(M):
    a,b = map(int,input().split())
    root[a].add(b)
    root[b].add(a)

task = deque([1])
itta = {1}

while len(task) > 0:
    now = task.popleft()
    additionanl = root[now] - itta #到達済みを排除している
    for i in additionanl: #ノードチェック
        ans[i] = now 
        itta.add(i)
    task.extend(list(additionanl)) #チェックしたノードを追加
print("Yes")
for i in range(2,N+1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N,M = map(int,input().split())

r = [[] for i in range(N+1)]

for i in range(M):
    a,b = map(int,input().split())
    r[a].append(b)
    r[b].append(a)

miteru = deque([1])
mita = {1}
res = [-1]*(N+1)

while  len(miteru) != 0: 
    now = miteru.popleft()
    x =set( r[now])
    x = x - mita
    for i in x:
        miteru.append(i)
        if res[i] == -1:res[i] =now
    mita.add(now)
    
print("Yes")
for i in res[2:]:
    print(i)
#print("\n".join(res))


Fixed submission:
from collections import deque
N,M = map(int,input().split())

root = [set()for i in range(N+1)]
ans = [0 for i in range(N+1)]

for i in range(M):
    a,b = map(int,input().split())
    root[a].add(b)
    root[b].add(a)

task = deque([1])
itta = {1}

while len(task) > 0:
    now = task.popleft()
    additionanl = root[now] - itta #到達済みを排除している
    for i in additionanl: #ノードチェック
        ans[i] = now 
        itta.add(i)
    task.extend(list(additionanl)) #チェックしたノードを追加
print("Yes")
for i in range(2,N+1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N,M = map(int,input().split())

r = [[] for i in range(N+1)]

for i in range(M):
    a,b = map(int,input().split())
    r[a].append(b)
    r[b].append(a)

miteru = deque([1])
mita = {1}
res = [-1]*(N+1)

while  len(miteru) != 0: 
    now = miteru.popleft()
    x =set( r[now])
    x = x - mita
    for i in x:
        miteru.append(i)
        if res[i] == -1:res[i] =now
    mita.add(now)
    
print("Yes")
for i in res[2:]:
    print(i)
#print("\n".join(res))


Fixed submission:
from collections import deque
N,M = map(int,input().split())

root = [set()for i in range(N+1)]
ans = [0 for i in range(N+1)]

for i in range(M):
    a,b = map(int,input().split())
    root[a].add(b)
    root[b].add(a)

task = deque([1])
itta = {1}

while len(task) > 0:
    now = task.popleft()
    additionanl = root[now] - itta #到達済みを排除している
    for i in additionanl: #ノードチェック
        ans[i] = now 
        itta.add(i)
    task.extend(list(additionanl)) #チェックしたノードを追加
print("Yes")
for i in range(2,N+1):
    print(ans[i])