Buggy python submission (verdict: Time Limit Exceeded):
import copy

#メイン部
N,M=map(int,input().split())

V=list(range(1,N+1))
H={v:set() for v in V}
L={v:None for v in V}

for i in range(M):
    v,w=map(int,input().split())
    H[v].add(w)
    H[w].add(v)

X=set()
Y={V[0]}

while X!=Y:
    Z=Y-X
    X=copy.deepcopy(Y)
    
    for v in Z:
        K=[u for u in H[v] if u not in Y]
        for x in K:
            Y.add(x)
            L[x]=v

if set(V)==X:
    print("Yes")
    for i in range(2,N+1):
        print(L[i])
else:
    print("No")

Fixed submission:
import copy
import collections

#メイン部
N,M=map(int,input().split())

V=list(range(1,N+1))
H={v:set() for v in V}
L={v:None for v in V}

for i in range(M):
    v,w=map(int,input().split())
    H[v].add(w)
    H[w].add(v)

Q=collections.deque()
Q.append(V[0])

L[1]=1
n=1

while Q:
    x=Q.popleft()
    for v in H[x]:
        if L[v]!=None:
            continue
        L[v]=x
        n+=1
        Q.append(v)

if n==N:
    print("Yes")
    for i in range(2,N+1):
        print(L[i])
else:
    print("No")

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

def Neighbohood(V,E,v):
    H=[]
    for w in V:
        if ((v,w) in E) or ((w,v) in E):
            H.append(w)

    return H

def bfs(V,E):
    W=[ v for v in V]
    Q=collections.deque([W[0]])
    searched = { v: False for v in W}
    searched[W[0]] = True
    L={v:None for v in W}
    n=1
    
    while len(Q) != 0:
        v=Q.popleft()
        Nei=Neighbohood(V,E,v)

        D=[x for x in Nei if searched[x]==False]
        
        for w in D:
            Q.append(w)
            L[w]=v
            searched[w] = True
            n+=1
            
    return (L,n)

#メイン部
N,M=map(int,input().split())

V=list(range(1,N+1))

E=[]
for i in range(M):
    v,w=map(int,input().split())
    E.append((v,w))

(L,n)=bfs(V,E)
if N==n:
    print("Yes")
    for i in range(2,N+1):
        print(L[i])
else:
    print("No")


Fixed submission:
import copy
import collections

#メイン部
N,M=map(int,input().split())

V=list(range(1,N+1))
H={v:set() for v in V}
L={v:None for v in V}

for i in range(M):
    v,w=map(int,input().split())
    H[v].add(w)
    H[w].add(v)

Q=collections.deque()
Q.append(V[0])

L[1]=1
n=1

while Q:
    x=Q.popleft()
    for v in H[x]:
        if L[v]!=None:
            continue
        L[v]=x
        n+=1
        Q.append(v)

if n==N:
    print("Yes")
    for i in range(2,N+1):
        print(L[i])
else:
    print("No")

Buggy python submission (verdict: Time Limit Exceeded):
import copy

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

V=list(range(1,N+1))
K={v:set() for v in V}
L={v:None for v in V}
    
for i in range(M):
    v,w=map(int,input().split())

    K[v].add(w)
    K[w].add(v)


X=set()
Y={V[0]}

while X!=Y:
    Z=copy.deepcopy(Y-X)
    X=copy.deepcopy(Y)

    for v in Z:
        for n in K[v]:
            if n not in Y:
                Y.add(n)
                L[n]=v
                

if set(V)==X:
    print("Yes")
    for i in range(2,N+1):
        print(L[i])
else:
    print("No")


Fixed submission:
import copy
import collections

#メイン部
N,M=map(int,input().split())

V=list(range(1,N+1))
H={v:set() for v in V}
L={v:None for v in V}

for i in range(M):
    v,w=map(int,input().split())
    H[v].add(w)
    H[w].add(v)

Q=collections.deque()
Q.append(V[0])

L[1]=1
n=1

while Q:
    x=Q.popleft()
    for v in H[x]:
        if L[v]!=None:
            continue
        L[v]=x
        n+=1
        Q.append(v)

if n==N:
    print("Yes")
    for i in range(2,N+1):
        print(L[i])
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
import networkx as nx
import collections

def bfs(G):
    V = [ v for v in G.nodes() ]
    Q = collections.deque([V[0]])
    searched = { v: False for v in G.nodes() }
    searched[V[0]] = True
    n=1
    H={v:None for v in G.nodes()}

    while len(Q) != 0:
        v = Q.popleft()
        edges = [ (v, i ) for (v, i) in G.edges(v) if not searched[i] ]
        for edge in edges:
            v, i = edge
            Q.append(i)
            searched[i] = True

            if H[i]==None:
                H[i]=v
                n+=1
                
    return (H,n)

G=nx.Graph()
N,M=map(int,input().split())
G.add_nodes_from(range(1,N+1))

for i in range(M):
    v,w=map(int,input().split())
    G.add_edge(v,w)

(H,n)=bfs(G)
if n!=N:
    print("No")
else:
    print("Yes")
    for i in range(2,N+1):
        print(H[i])



Fixed submission:
import copy
import collections

#メイン部
N,M=map(int,input().split())

V=list(range(1,N+1))
H={v:set() for v in V}
L={v:None for v in V}

for i in range(M):
    v,w=map(int,input().split())
    H[v].add(w)
    H[w].add(v)

Q=collections.deque()
Q.append(V[0])

L[1]=1
n=1

while Q:
    x=Q.popleft()
    for v in H[x]:
        if L[v]!=None:
            continue
        L[v]=x
        n+=1
        Q.append(v)

if n==N:
    print("Yes")
    for i in range(2,N+1):
        print(L[i])
else:
    print("No")