Problem p02678 (python)

Fixed submission:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right

n,m=n1()
ab=n3(m)

node=defaultdict(list)
for a,b in ab:
    node[a].append(b)
    node[b].append(a)
    
p=deque([1])
d=[0]*(n+1)
while len(p)>0:
    c=p.popleft()
    for i in node[c]:
        if d[i]==0:
            d[i]=c
            p.append(i)
            
print("Yes")
for i in range(2,n+1):
    print(d[i])

Buggy submission (verdict: Runtime Error):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
from collections import Counter,deque,defaultdict
# import itertools
# import math
import networkx as nx
# from bisect import bisect_left,bisect_right
n,m=n1()
ab=n3(m)

ans={}
d=[0]*(n+1)
p=[1]
p2=[]
while len(ans)<n-1:
    for c in p:
        d[c]=1
        for a,b in ab:
            if a==c and d[b]==0:
                p2.append(b)
                d[b]=1
                ans[b]=a
            if b==c and d[a]==0:
                p2.append(a)
                d[a]=1
                ans[a]=b
    p=p2.copy()
    p2=[]

A=list(ans.items())
A.sort(key=lambda x:x[0])
print("Yes")
for line in A:
    print(line[1])

Buggy submission (verdict: Runtime Error):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [[input().split()] for _ in range(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes) if b else print(no)
from collections import Counter,deque,defaultdict
# import itertools
# import math
import networkx as nx
# from bisect import bisect_left,bisect_right
n,m=n1()
ab=n3(m)

ans={}
d=[0]*(n+1)
p=[1]
p2=[]
while len(ans)<n-1:
    for c in p:
        d[c]=1
        for a,b in ab:
            if a==c and d[b]==0:
                p2.append(b)
                d[b]=1
                ans[b]=a
            if b==c and d[a]==0:
                p2.append(a)
                d[a]=1
                ans[a]=b
    p=p2.copy()
    p2=[]

A=list(ans.items())
A.sort(key=lambda x:x[0])
print("Yes")
for line in A:
    print(line[1])