Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M=list(map(int,input().split()))
AB=[set() for i in range(N+1)]
room=[0]*(N+1)
pre=[None]*(N+1)
def bfs(i):#１に到達
    Done=set()
    Done.add(i)
    d=deque([i])
    child=set()
    child.add(i)
    count=1
    while(d):
        k=d.popleft()
        if k not in child:
            count+=1
            child=child.union(Done)
        room[k]=count
        for i in AB[k]:
            if i not in Done:
                pre[i]=k
                Done.add(i)
                d.append(i)





for i in range(M):
    A,B=list(map(int,input().split()))
    AB[A].add(B)
    AB[B].add(A)

flag=True
bfs(1)
if sum(room)==0:
    print("No:")
    exit()
for i in range(2,N+1):
    if flag:
        print("Yes")
        flag=False
    if pre[i] is not None:
        print(pre[i])




Fixed submission:
from collections import deque
N,M=list(map(int,input().split()))
AB=[set() for i in range(N+1)]
room=[0]*(N+1)
pre=[None]*(N+1)
def bfs(i):#１に到達
    Done=set()
    Done.add(i)
    d=deque([i])
    # child=set()
    # child.add(i)
    # count=1
    while(d):
        k=d.popleft()
        # if k not in child:
        #     count+=1
        #     child=child.union(Done)
        # room[k]=count
        for i in AB[k]:
            if i not in Done:
                pre[i]=k
                Done.add(i)
                d.append(i)





for i in range(M):
    A,B=list(map(int,input().split()))
    AB[A].add(B)
    AB[B].add(A)

flag=True
bfs(1)
if pre.count(None)<=N+1:
    for i in range(2,N+1):
        if flag:
            print("Yes")
            flag=False
        if pre[i] is not None:
            print(pre[i])
else:print("No")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M=list(map(int,input().split()))
AB=[set() for i in range(N+1)]
node_list=[None]*(N+1)
class node():
    def __init__(self,i):
        self.node=i
        self.prev=None
def bfs(i):#１に到達
    Done=set()
    Done.add(i)
    d=deque([i])

    while(d):

        kako = set()
        k=d.popleft()
        if node_list[k] is None:
            n = node(k)
        else:
            n=node_list[k]
        for i in AB[k]:
            if i not in Done:
                jk=node(i)
                jk.prev=n
                node_list[i]=jk
                Done.add(i)
                d.append(i)
                if i==1:
                    return True,jk


        node_list[k]=n
    return False,0




for i in range(M):
    A,B=list(map(int,input().split()))
    AB[A].add(B)
    AB[B].add(A)
flag1=True
for i in range(2,N+1):
    flag,jk=bfs(i)
    if flag:
        if flag1:
            print("Yes")
            flag1=False

        while(jk.prev.node!=i):
            jk=jk.prev
        print(jk.node)


Fixed submission:
from collections import deque
N,M=list(map(int,input().split()))
AB=[set() for i in range(N+1)]
room=[0]*(N+1)
pre=[None]*(N+1)
def bfs(i):#１に到達
    Done=set()
    Done.add(i)
    d=deque([i])
    # child=set()
    # child.add(i)
    # count=1
    while(d):
        k=d.popleft()
        # if k not in child:
        #     count+=1
        #     child=child.union(Done)
        # room[k]=count
        for i in AB[k]:
            if i not in Done:
                pre[i]=k
                Done.add(i)
                d.append(i)





for i in range(M):
    A,B=list(map(int,input().split()))
    AB[A].add(B)
    AB[B].add(A)

flag=True
bfs(1)
if pre.count(None)<=N+1:
    for i in range(2,N+1):
        if flag:
            print("Yes")
            flag=False
        if pre[i] is not None:
            print(pre[i])
else:print("No")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M=list(map(int,input().split()))
AB=[set() for i in range(N+1)]
node_list=[None]*(N+1)
class node():
    def __init__(self,i):
        self.node=i
        self.prev=None
def bfs(i):#１に到達
    Done=set()
    Done.add(i)
    d=deque([i])
    child = set()
    child.add(i)
    while(d):

        kako = set()
        k=d.popleft()
        if node_list[k] is None:
            n = node(k)
        else:
            n=node_list[k]
        for i in AB[k]:
            if i not in Done:
                jk=node(i)
                jk.prev=n
                node_list[i]=jk
                Done.add(i)
                d.append(i)
                child.add(i)
                if i==1:
                    return True,jk


        node_list[k]=n
    return False,0




for i in range(M):
    A,B=list(map(int,input().split()))
    AB[A].add(B)
    AB[B].add(A)
flag1=True
for i in range(2,N+1):
    flag,jk=bfs(i)
    if flag:
        if flag1:
            print("Yes")
            flag1=False

        while(jk.prev.node!=i):
            jk=jk.prev
        print(jk.node)


Fixed submission:
from collections import deque
N,M=list(map(int,input().split()))
AB=[set() for i in range(N+1)]
room=[0]*(N+1)
pre=[None]*(N+1)
def bfs(i):#１に到達
    Done=set()
    Done.add(i)
    d=deque([i])
    # child=set()
    # child.add(i)
    # count=1
    while(d):
        k=d.popleft()
        # if k not in child:
        #     count+=1
        #     child=child.union(Done)
        # room[k]=count
        for i in AB[k]:
            if i not in Done:
                pre[i]=k
                Done.add(i)
                d.append(i)





for i in range(M):
    A,B=list(map(int,input().split()))
    AB[A].add(B)
    AB[B].add(A)

flag=True
bfs(1)
if pre.count(None)<=N+1:
    for i in range(2,N+1):
        if flag:
            print("Yes")
            flag=False
        if pre[i] is not None:
            print(pre[i])
else:print("No")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N,M=list(map(int,input().split()))
AB=[set() for i in range(N+1)]
node_list=[None]*(N+1)
class node():
    def __init__(self,i):
        self.node=i
        self.prev=None
def bfs(i):#１に到達
    Done=set()
    Done.add(i)
    d=deque([i])
    count = 1
    a = set()
    a.add(i)
    bro = {0: a}
    second=False
    while(d):

        kako = set()
        k=d.popleft()
        if node_list[k] is None:
            n = node(k)
        else:
            n=node_list[k]
        for i in AB[k]:
            if i not in Done:
                jk=node(i)
                jk.prev=n
                node_list[i]=jk
                kako.add(i)
                Done.add(i)
                d.append(i)
                if i==1:
                    return True,jk

        if k  in bro[count-1]:
            if count not in bro:
                bro[count]=kako
            else:
                bro[count] = bro[count].union(kako)
        else:#入ってなかった場合
            count+=1

            if count not in bro:
                bro[count]=kako
            else:
                bro[count] = bro[count].union(kako)
        node_list[k]=n
    return False,0




for i in range(M):
    A,B=list(map(int,input().split()))
    AB[A].add(B)
    AB[B].add(A)
flag1=True
for i in range(2,N+1):
    flag,jk=bfs(i)
    if flag:
        if flag1:
            print("Yes")
            flag1=False

        while(jk.prev.node!=i):
            jk=jk.prev
        print(jk.node)


Fixed submission:
from collections import deque
N,M=list(map(int,input().split()))
AB=[set() for i in range(N+1)]
room=[0]*(N+1)
pre=[None]*(N+1)
def bfs(i):#１に到達
    Done=set()
    Done.add(i)
    d=deque([i])
    # child=set()
    # child.add(i)
    # count=1
    while(d):
        k=d.popleft()
        # if k not in child:
        #     count+=1
        #     child=child.union(Done)
        # room[k]=count
        for i in AB[k]:
            if i not in Done:
                pre[i]=k
                Done.add(i)
                d.append(i)





for i in range(M):
    A,B=list(map(int,input().split()))
    AB[A].add(B)
    AB[B].add(A)

flag=True
bfs(1)
if pre.count(None)<=N+1:
    for i in range(2,N+1):
        if flag:
            print("Yes")
            flag=False
        if pre[i] is not None:
            print(pre[i])
else:print("No")