Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False for i in range(k+1)]
for i in range(k+1):
    for j in range(n):
        if i-a[j]>=0:
            dp[i]|=(dp[i-a[j]]^(True))
if dp[k]:
    print("First")
else:
    print("Second")

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[False for i in range(k+1)]
for i in range(k+1):
    for j in range(n):
        if i-a[j]>=0:
            dp[i]|=(dp[i-a[j]]^(True))
if dp[k]:
    print("First")
else:
    print("Second")
Buggy python submission (verdict: Runtime Error):
print( "second" if all(a[i]%2==0 for i in range(N)) else "first" )

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]

print( "second" if all(a[i]%2==0 for i in range(n)) else "first" )
Buggy python submission (verdict: Runtime Error):
N,X=map(int,input().split())

a,p=[1],[1]

for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def solve(n,x): #n,x
    if n==0:
        if x<=0:
            return 0
        else:
            return 1
    elif x<=1+a[N-1]:
        return  solve(N-1,X-1)
    else:
        return p[N-1]+1+solve(N-1,X-2-a[N-1])

print(solve(N,X))




Fixed submission:
N,X=map(int,input().split())

a,p=[1],[1]

for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)

def solve(n,x): #n,x
    if n==0:
        if x<=0:
            return 0
        else:
            return 1
    elif x<=1+a[n-1]:
        return  solve(n-1,x-1)
    else:
        return p[n-1]+1+solve(n-1,x-2-a[n-1])

print(solve(N,X))
Buggy python submission (verdict: Runtime Error):
n=int(input())
e=[0]*(n+1)
for i in range(2,n+1):
    cur=i
    for j in range(2,i+1):
        while cuur%j==0:
            e[j]+=1
            cur//=j
def num(m):
    return len(list(filter(lambda  x: x>=m-1,e)))

print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)


Fixed submission:
n=int(input())
e=[0]*(n+1)
for i in range(2,n+1):
    cur=i
    for j in range(2,i+1):
        while cur%j==0:
            e[j]+=1
            cur//=j
def num(m):
    return len(list(filter(lambda  x: x>=m-1,e)))

print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
ans=0
for i in range(1,M//N+1):
    if M%i==0:
        ans=max(i,ans)

print(ans)

Fixed submission:
import  fractions
import math
import bisect
N,M=map(int,input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

ans=0
cnt=make_divisors(M)
tmp=bisect.bisect_right(cnt,M/N)

print(cnt[tmp-1])
Buggy python submission (verdict: Runtime Error):
S=input()
T=input()
L=len(S)

dds=defaultdict(int)
ddt=defaultdict(int)

for i in range(L):
    s=S[i]
    t=T[i]
    if dds[s]==0:
        dds[s]=t
    else:
        if dds[s]!=t:
            print("No")
            exit()
    if ddt[t]==0:
        ddt[t]=s
    else:
        if ddt[t]!=s:
            print("No")
            exit()
print("Yes")

Fixed submission:
from collections import defaultdict

S=input()
T=input()
L=len(S)

dds=defaultdict(int)
ddt=defaultdict(int)

for i in range(L):
    s=S[i]
    t=T[i]
    if dds[s]==0:
        dds[s]=t
    else:
        if dds[s]!=t:
            print("No")
            exit()
    if ddt[t]==0:
        ddt[t]=s
    else:
        if ddt[t]!=s:
            print("No")
            exit()
print("Yes")
Buggy python submission (verdict: Runtime Error):
N,x=map(int,input().split())
a=list(input().split())

a.sort()

ans=0
tmp=0
for i in  range(len(a)):
  tmp+=int(a[i])

if tmp==x:
  print(N)
  exit()

for i in range(0,N):
  if x-int(a[i])>=0:
    ans+=1
    x-=int(a[i])
  else:
    print(ans)
    break

if a[0]>x:
  print(0)

Fixed submission:
N,x=map(int,input().split())
a=list(map(int,input().split()))

a.sort()

ans=0

if x==sum(a):
  print(N)
  exit()
  
for i in range(N):
  x-=a[i]
  if x<0:
    print(i)
    exit()
else:
  print(N-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
S=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(m):
    l,r=map(int,input().split())
    S[l][r]+=1

for i in range(1,n+1):
    for j in range(1,n):
        S[i][j+1]+=S[i][j]

for i in range(q):
    a,b=map(int,input().split())
    ans=0
    for y in range(a,b+1):
        ans+=S[y][b]-S[y][a-1]
    print(ans)


Fixed submission:
n,m,q=map(int,input().split())
S=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(m):
    l,r=map(int,input().split())
    S[l][r]+=1

for i in range(1,n+1):
    for j in range(1,n):
        S[i][j+1]+=S[i][j]

for i in range(q):
    a,b=map(int,input().split())
    ans=0
    for y in range(a,b+1):
        ans+=S[y][b]-S[y][a-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
S=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(m):
    l,r=map(int,input().split())
    S[l][r]+=1

for i in range(q):
    a,b=map(int,input().split())
    ans=0
    for y in range(a,b+1):
        for x in range(a,b+1):
            ans+=S[x][y]
    print(ans)


Fixed submission:
n,m,q=map(int,input().split())
S=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(m):
    l,r=map(int,input().split())
    S[l][r]+=1

for i in range(1,n+1):
    for j in range(1,n):
        S[i][j+1]+=S[i][j]

for i in range(q):
    a,b=map(int,input().split())
    ans=0
    for y in range(a,b+1):
        ans+=S[y][b]-S[y][a-1]
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,q=map(int,input().split())
S=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(m):
    l,r=map(int,input().split())
    S[l][r]+=1

for i in range(q):
    a,b=map(int,input().split())
    ans=0
    for y in range(a,b+1):
        for x in range(a,b+1):
            ans+=S[x][y]
    print(ans)


Fixed submission:
n,m,q=map(int,input().split())
S=[[0 for i in range(n+1)] for j in range(n+1)]
for i in range(m):
    l,r=map(int,input().split())
    S[l][r]+=1

for i in range(1,n+1):
    for j in range(1,n):
        S[i][j+1]+=S[i][j]

for i in range(q):
    a,b=map(int,input().split())
    ans=0
    for y in range(a,b+1):
        ans+=S[y][b]-S[y][a-1]
    print(ans)
Buggy python submission (verdict: Runtime Error):
import math
n=int(input())
A=list(map(int,input().split()))
gd=1
tmp=A[0]
for i in range(n-1):
    gd=math.gcd(A[i+1],A[i])
    tmp*=A[i+1]
lcm=tmp//gd
lcm-=1
ans=0
for a in A:
    ans+=lcm%a

print(ans)

Fixed submission:
import fractions
n=int(input())
A=list(map(int,input().split()))
gd=1
tmp=A[0]
for i in range(n-1):
    gd=fractions.gcd(A[i+1],A[i])
    tmp*=A[i+1]
lcm=tmp//gd
lcm-=1
ans=0
for a in A:
    ans+=lcm%a

print(ans)

Buggy python submission (verdict: Runtime Error):
import math
import functools
n=int(input())
a=list(map(int,input().split()))
tmp=1
for f in a:
    tmp*=f
gcd=functools.reduce(math.gcd, a)
lcm=tmp//gcd
lcm-=1
ans=0
for f in a:
    ans+=lcm%f
print(ans)

Fixed submission:
import fractions
n=int(input())
A=list(map(int,input().split()))
gd=1
tmp=A[0]
for i in range(n-1):
    gd=fractions.gcd(A[i+1],A[i])
    tmp*=A[i+1]
lcm=tmp//gd
lcm-=1
ans=0
for a in A:
    ans+=lcm%a

print(ans)
Buggy python submission (verdict: Runtime Error):
s=list(input())

K=int(input())

L=[]

for i in range (1,K+1):
    for j in range (0, len(s)-i+1):
        L.append("".join(s[j:j+1]))

L=sorted(set(L))

print(L[K-1])



Fixed submission:
s=list(input())

K=int(input())

L=[]

for i in range (1,K+1):
    for j in range (0, len(s)-i+1):
        L.append("".join(s[j:j+i]))

L=sorted(set(L))

print(L[K-1])
Buggy python submission (verdict: Runtime Error):
#tempt
s=input()
t=input()
lt=len(t)
ls=len(s)
cnt=0
flag=True

for i in range(lt):
    for j in range(ls):
        if t[i]==s[j]:
            bs=j
            bt=i
            af=j
            at=j
            check=True
            while bs>0 and bt>0: #before
                if s[bs]=="?" or s[bs]==t[bt]:
                    continue
                else:
                    check=False
                bs-=1
                bt-=1
            if bt>0:
                check=False
            while af < ls and at < lt:  # before
                if s[af] == "?" or s[af] == t[at]:
                    continue
                else:
                    check = False
                af += 1
                at += 1
            if at != lt-1:
                check = False
        if not check:
            flag=False
        else:
            flag=True
    if flag:
        continue
    else:
        print("UNRESTORABLE")
        exit()




Fixed submission:
S=input()
T=input()
tmp=[]
for i in range(len(S)):
    flag=True
    for j in range(min(len(T),len(S)-i)):
        if S[i+j]==T[j] or S[i+j]=="?" or T[j]=="?":
            continue
        else:
            flag=False
    if flag:
        rec=S[:i]+T+S[i+len(T):]
        if len(rec)==len(S):
            rec=rec.replace("?","a")
            tmp.append(rec)
if tmp==[]:
    print("UNRESTORABLE")
    exit()
tmp.sort()
print(tmp[0])
Buggy python submission (verdict: Runtime Error):
print(input()[0:len(input())-8])

Fixed submission:
s=input()
print(s[0:len(s)-8])
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))

import  bisect

D.sort()
T.sort()
cnt=0
for i in range(M):
    a=bisect.bisect_right(D,T[i])
    b=bisect.bisect_left(D,T[i])
    if a-b>0:
        D.remove(D[a-1])
        cnt+=1
    else:
        print("NO")
        exit()

if cnt==M:
    print("YES")

Fixed submission:
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))

import  bisect
from collections import  Counter
D.sort()
T.sort()
tmpa=Counter(D)
tmpt=Counter(T)
cnt=0
for i in range(M):
    hnt=T[i]
    v=True
    if tmpt[hnt]<=tmpa[hnt]:
        continue
    else:
        v=False
        print("NO")
        exit()

if v:
    print("YES")

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))

import  bisect

D.sort()
T.sort()
cnt=0
for i in range(M):

    if bisect.bisect_right(D,T[i])-bisect.bisect_left(D,T[i])>0:
        D.remove(D[bisect.bisect_right(D,T[i])-1])
        cnt+=1
    else:
        print("NO")
        exit()

if cnt==M:
    print("YES")

Fixed submission:
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))

import  bisect
from collections import  Counter
D.sort()
T.sort()
tmpa=Counter(D)
tmpt=Counter(T)
cnt=0
for i in range(M):
    hnt=T[i]
    v=True
    if tmpt[hnt]<=tmpa[hnt]:
        continue
    else:
        v=False
        print("NO")
        exit()

if v:
    print("YES")
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import dijkstra,floyd_warshall
from scipy.sparse import csr_matrix
from  itertools import permutations

N,M,R=map(int,input().split())
r=[int(x)-1 for x in input().split()]
A=[]
B=[]
C=[]
for i in range(M):
    x,y,z=map(int,input().split())
    A.append(x-1)
    B.append(y-1)
    C.append(z)

d=csr_matrix((C,(A,B)),shape=(N,N))
tr=floyd_warshall(d)
ans=float('inf')

for tmp in permutations(r):
    cnt=0
    for i in range(len(r)-1):
        cnt+=tr[tmp[i]][tmp[i+1]]
    ans=min(ans,cnt)

print(int(ans))




Fixed submission:
from scipy.sparse.csgraph import dijkstra,floyd_warshall
from scipy.sparse import csr_matrix
from  itertools import permutations

N,M,R=map(int,input().split())
r=[int(x)-1 for x in input().split()]
dist=[[0 for _ in range(N)] for _ in range(N)]
for i in range(M):
    x,y,z=map(int,input().split())
    dist[x-1][y-1]=z
    dist[y-1][x-1]=z
tr=floyd_warshall(dist)
ans=10**12
for tmp in permutations(r):
    cnt=0
    for i in range(R-1):
        cnt+=tr[tmp[i]][tmp[i+1]]
    ans=min(ans,cnt)

print(int(ans))

Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import dijkstra,floyd_warshall
from scipy.sparse import csr_matrix
from  itertools import permutations

N,M,R=map(int,input().split())
r=[int(x)-1 for x in input().split()]
A=[]
B=[]
C=[]
for i in range(M):
    x,y,z=map(int,input().split())
    A.append(x-1)
    B.append(y-1)
    C.append(z)

d=csr_matrix((C,(A,B)),shape=(N,N))
tr=floyd_warshall(d)

ans=float('inf')
for tmp in permutations(r):
    cnt=0
    for i in range(len(tmp)-1):
        cnt+=tr[tmp[i]][tmp[i+1]]
    ans=min(ans,cnt)

print(int(ans))



Fixed submission:
from scipy.sparse.csgraph import dijkstra,floyd_warshall
from scipy.sparse import csr_matrix
from  itertools import permutations

N,M,R=map(int,input().split())
r=[int(x)-1 for x in input().split()]
dist=[[0 for _ in range(N)] for _ in range(N)]
for i in range(M):
    x,y,z=map(int,input().split())
    dist[x-1][y-1]=z
    dist[y-1][x-1]=z
tr=floyd_warshall(dist)
ans=10**12
for tmp in permutations(r):
    cnt=0
    for i in range(R-1):
        cnt+=tr[tmp[i]][tmp[i+1]]
    ans=min(ans,cnt)

print(int(ans))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
bb=set(a)
for i in range(n-1):
    tm=a[i+1]-a[i]
    bb.add(tm)
cv=list(bb)
cv.sort()

if k in cv:
    print("POSSIBLE")
    exit()

if max(cv)<k:
    print("IMPOSSIBLE")
    exit()

if n==1:
    if a[0]==k:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    exit()

xc=0
cb=False
if cv[0]==1:
    xc=cv[1]
else:
    xc=cv[0]

for i in range(len(cv)):
    if cv[i]%xc!=0:
        cb=True

if k<=max(cv):
    if cb:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    exit()
    
print("IMPOSSIBLE")

Fixed submission:
import fractions
n,k=map(int,input().split())
a=list(map(int,input().split()))
if max(a)<k:
    print("IMPOSSIBLE")
    exit()
t=a[0]
if n!=1:
    for i in range(1,n):
        t=fractions.gcd(t,a[i])

if k%t==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
bb=set(a)
for i in range(n-1):
    tm=a[i+1]-a[i]
    bb.add(tm)
cv=list(bb)
cv.sort()

if k in cv:
    print("POSSIBLE")
    exit()

if max(cv)<k:
    print("IMPOSSIBLE")
    exit()

if n==1:
    if a[0]==k:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    exit()

xc=0
cb=False
if cv[0]==1:
    xc=cv[1]
else:
    xc=cv[0]

for i in range(len(cv)):
    if cv[i]%xc!=0:
        cb=True

if k<=max(cv):
    if cb:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
    exit()

Fixed submission:
import fractions
n,k=map(int,input().split())
a=list(map(int,input().split()))
if max(a)<k:
    print("IMPOSSIBLE")
    exit()
t=a[0]
if n!=1:
    for i in range(1,n):
        t=fractions.gcd(t,a[i])

if k%t==0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
import  itertools

n,p=map(int,input().split())
a=list(map(int,input().split()))
ans=0
nums=[0,1]


def judge(C):
    er=0
    for i,cnt in enumerate (C):
        if cnt==1:
            er+=a[i]
    if er%2==p:
        return True
    else:
        return False


for biscuits in itertools.product(nums,repeat=n):
    t=list(biscuits)
    if judge(t):
        ans+=1

print(ans)

Fixed submission:
n,p=map(int,input().split())
a=list(map(int,input().split()))
odd=[0]*n
even=[0]*n

if a[0]%2==0:
    even[0]=2
else:
    odd[0]=1
    even[0] = 1

for i in range(n-1):
    if a[i+1]%2==0:
        odd[i+1]+=odd[i]*2
        even[i+1]+=even[i]*2
    else:
        odd[i+1]+=even[i]+odd[i]
        even[i+1]+=odd[i]+even[i]

if p==0:
    print(even[n-1])
else:
    print(odd[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    q=int(input())
    h.append(q)
left=0
right=max(h)+1
def en(t):
    cnt=0
    for i in range(n):
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)!=0:
            cnt+=((h[i]-b*t)//((a-b))+1)
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)==0:
            cnt+=((h[i]-b*t)//(a-b))
    if cnt<=t:
        return  True
    return  False
while left+1<right:
    tmp=(left+right)//2
    if en(tmp):
        right=tmp
    else:
        left=tmp
print(right)

Fixed submission:
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    q=int(input())
    h.append(q)
left=0
right=max(h)+1
def en(t):
    cnt=0
    for i in range(n):
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)!=0:
            cnt+=((h[i]-b*t)//((a-b))+1)
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)==0:
            cnt+=((h[i]-b*t)//(a-b))
    if cnt<=t:
        return  True
    return  False
while left+1<right:
    tmp=(left+right)//2
    if en(tmp):
        right=tmp
    else:
        left=tmp
print(right)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
h = list(map(int, input().split()))
 
DP = [0]
for i in range(N-1):
    act = float("inf")
    for k in range(K):
        if i-k < 0 : break
        act = min(DP[-1-k] + abs(h[i-k]-h[i+1]) , act)
    DP += [act]
 
print(DP[-1])


Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [100000000000 for _ in range(n)]
dp[0] = 0
for i in range(n):
    for j in range(min(i+1,k+1)):
        dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])
print(dp[-1])
Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
temp = a % 500
if temp <= b:
  print("Yes")
else:
  print("No")

Fixed submission:
a = int(input())
b = int(input())
temp = a % 500
if temp <= b:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
a = input()
b = input()
if a % 500 <= b:
  print("Yes")
else:
  print("No")

Fixed submission:
a = int(input())
b = int(input())
temp = a % 500
if temp <= b:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a  = list(map(int,input().split()))

a.sort(reverse=True)
dic = {a[0]:1}
ans = 0

for i in range(1,n):
    h = a[i]
    max_h = list(dic)[0]
    
    
    
    if h == max_h:
        dic[h] += 1
        ans += h
    
    else:
        if h in dic:
            dic[h] += 2
            dic[max_h] -= 1
            ans += max_h
        
        else:
            dic[h] = 2
            dic[max_h] -= 1
            ans += max_h
        
        if dic[max_h] == 0:
            del dic[max_h]
    
    

print(ans)
            

Fixed submission:
n = int(input())
a  = list(map(int,input().split()))

a.sort(reverse=True)
dic = {a[0]:1}
ans = 0

for i in range(1,n):
    h = a[i]
    max_h = next(iter(dic))
    
    
    
    if h == max_h:
        dic[h] += 1
        ans += h
    
    else:
        if h in dic:
            dic[h] += 2
            dic[max_h] -= 1
            ans += max_h
        
        else:
            dic[h] = 2
            dic[max_h] -= 1
            ans += max_h
        
        if dic[max_h] == 0:
            del dic[max_h]
    
    

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

l = list(map(int,input().split()))

ans = 1

for i in l:
    ans *= i

if ans > 10**18:
    print(-1)

else:
    print(ans)

Fixed submission:
n = int(input())
 
l = list(map(int,input().split()))
 
if 0 in l:
    print(0)
    exit()
    
ans = 1
 
for i in l:
    ans *= i
    
    if ans > 10**18:
        print(-1)
        exit()

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

n , m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]

l = [[0 for i in range(n)] for i in range(n)]

a = np.array(l)

for i in range(m):
    l[ab[i][0 ]-1][ab[i][1]-1] = 1
    l[ab[i][1]-1][ab[i][0]-1] = 1

a = np.array(l)
d, p = shortest_path(a, return_predecessors=True, indices=0, method='D')

if float('inf') in d:
    print('No')
    

else:
    print('Yes')

for i in p[1:]:
    print(i+1)


Fixed submission:
from collections import deque

n, m = map(int,input().split())
graph = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
    
ans = [0]*(n+1)
seen = [False]*(n+1)

que = deque()
que.append(1)

while len(que) != 0:
    k = que.popleft()
    seen[k] = True
    
    for i in graph[k]:
        if seen[i]:
            continue
        ans[i] = k
        que.append(i)
        seen[i] = True

ans = ans[2:]

for i in ans:
    if i == 0:
        print('No')
        exit()

print('Yes')

for i in ans:
    print(i)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

n , m = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(m)]

l = [[0 for i in range(n)] for i in range(n)]

a = np.array(l)

for i in range(m):
    l[ab[i][0 ]-1][ab[i][1]-1] = 1
    l[ab[i][1]-1][ab[i][0]-1] = 1

a = np.array(l)
d, p = shortest_path(a, return_predecessors=True, indices=0)

if float('inf') in d:
    print('No')
    

else:
    print('Yes')

for i in p[1:]:
    print(i+1)


Fixed submission:
from collections import deque

n, m = map(int,input().split())
graph = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)
    
ans = [0]*(n+1)
seen = [False]*(n+1)

que = deque()
que.append(1)

while len(que) != 0:
    k = que.popleft()
    seen[k] = True
    
    for i in graph[k]:
        if seen[i]:
            continue
        ans[i] = k
        que.append(i)
        seen[i] = True

ans = ans[2:]

for i in ans:
    if i == 0:
        print('No')
        exit()

print('Yes')

for i in ans:
    print(i)