Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03943 (python)

Fixed submission:
C = [int(_) for _ in input().split()]
C.sort()
print("Yes" if C[0] + C[1] == C[2] else "No")

Buggy submission (verdict: Runtime Error):
import sys

def solve():
    input = sys.stdin.readline
    C = [int(i) for i in input().spit()]
    C.sort()
    if C[0] + C[1] == C[2]: print("Yes")
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()
Problem p03958 (python)

Fixed submission:
K, T = map(int, input().split())
A = [int(a) for a in input().split()]
A.sort()
sumA = 0
for a in A[:T-1]: sumA += a
print(max(0, A[T-1] - 1 - sumA))

Buggy submission (verdict: Runtime Error):
K, T = map(int, input().split())
A = [int(a) for a in input().split()]
A.sort()
sumA = 0
for a in A[:N-1]: sumA += a
print(max(0, A[N-1] - 1 - sumA))
Problem p03997 (python)

Fixed submission:
A = int(input())
B = int(input())
H = int(input())
print((A+B)*H//2)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
H = int(input())
print((A+b)*H//2)
Problem p04014 (python)

Fixed submission:
import math
n = int(input())
s = int(input())

def f(b, n):
    ans = 0
    while b <= n:
        ans += n%b
        n //= b
    ans += n
    return ans

if n == s:
    print(n+1)
elif n < s:
    print(-1)
else:
    limit = math.ceil(math.sqrt(n))
    for b in range(2, limit + 1):
        if f(b, n) == s:
            print(b)
            break
    else:
        for p in range(limit, 0 ,-1):
            if s - p >= 0 and n-s+p > 0 and (n-s+p)//p > limit:
                b = (n-s+p)//p
                if f(b, n) == s:
                    print(b)
                    break
        else:
            print(-1)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
s = int(input())

def f(b, n):
    ans = 0
    while b <= n:
        ans += n%b
        n //= b
    ans += n
    return ans

if n == s:
    print(n+1)
else:
    for b in range(2, math.ceil(math.sqrt(n)) + 1):
        if f(b, n) == s:
            print(b)
            break
    else:
        for p in range(1, math.ceil(math.sqrt(n)) + 1):
            if s - p >= 0 and n-s+p > 0:
                b = round((n-s+p)/p, )
                if f(b, n) == s:
                    print(b)
                    break
        else:
            print(-1)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
s = int(input())

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + (n%b)

if n == s:
    print(n+1)
elif n < s:
    print(-1)
else:
    for b in range(2, int(math.sqrt(n)) + 1):
        if f(b, n) == s:
            print(b)
            break
    else:
        for p in range(1, int(math.sqrt(n)) + 1):
            b = int(((n-s)/p) + 1)
            if f(b, n) == s:
                print(b)
                break
        else:
            print(-1)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
s = int(input())

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + (n%b)

if n == s:
    print(n+1)
elif n == 1:
    print(-1)
else:
    for b in range(2, int(math.sqrt(n)) + 1):
        if f(b, n) == s:
            print(b)
            break
    else:
        for p in range(1, int(math.sqrt(n)) + 1):
            b = int(((n-s)/p) + 1)
            if f(b, n) == s:
                print(b)
                break
        else:
            print(-1)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
s = int(input())

def f(b, n):
    if n < b:
        return n
    else:
        return f(b, n//b) + (n%b)

if n == s:
    print(n+1)
elif n == 1:
    print(1 if s == 1 else -1)
else:
    for b in range(2, int(math.sqrt(n)) + 1):
        if f(b, n) == s:
            print(b)
            break
    else:
        for p in range(1, int(math.sqrt(n)) + 1):
            b = int(((n-s)/p) + 1)
            if f(b, n) == s:
                print(b)
                break
        else:
            print(-1)
Problem p04032 (python)

Fixed submission:
S = list(input())
i = 0
while i <= len(S)-3:
    if S[i] == S[i+1]:
        print(i+1, i+2)
        break
    elif S[i] == S[i+2]:
        print(i+1, i+3)
        break
    i += 1
else:
    if S[i] == S[i+1]:
        print(i+1, i+2)
    else:
        print(-1, -1)

Buggy submission (verdict: Runtime Error):
S = list(input())
i = 0
while i < len(S)-2:
    j = i+1
    if S[i] == S[j]:
        print(i, j)
        break
    else:
        k = i+2
        if S[i] == S[k] or S[j] == S[k]:
            print(i, k)
            break
        else:
            i += 3
else:
    if i == len(S) - 2:
        if S[i] == S[i+1]:
            print(i, i+1)
        elif S[i] == S[i+2]:
            print(i, i+2)
        elif S[i+1] == S[i+2]:
            print(i+1, i+2)
        else:
            print(-1, -1)
    elif i == len(S) - 1 and S[i] == S[i+1]:
        print(i, i+1)
    else:
        print(-1, -1)
Problem p02536 (python)

Fixed submission:
class UnionFind:
  def __init__(self, n):
    self.g = [i for i in range(n)]
    self.n = n
  def whichclass(self, x):
    if self.g[x]==x:
      return x
    else:
      self.g[x] = self.whichclass(self.g[x])
      return self.g[x]
  def union(self, x, y):
    cx = self.whichclass(x)
    cy = self.whichclass(y)
    if cx==cy:
      return
    minc = min(cx, cy)
    maxc = max(cx, cy)
    self.g[maxc] = minc
  def __getitem__(self, x):
    return self.whichclass(x)
  
N, M = map(int, input().split())
UF = UnionFind(N)
for i in range(M):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  UF.union(a, b)
count = [0 for i in range(N)]
for i in range(N):
  count[UF[i]] = 1
print(sum(count)-1)

Buggy submission (verdict: Runtime Error):
class UnionFind:
  def __init__(self, n):
    self.class = [i for i in range(n)]
    self.n = n
  def whichclass(self, x):
    if self.class[x]==x:
      return x
    else:
      self.class[x] = self.whichclass(self.class[x])
      return self.class[x]
  def union(self, x, y):
    cx = self.whichclass(x)
    cy = self.whichclass(y)
    if cx==cy:
      return
    minc = min(cx, cy)
    maxc = max(cx, cy)
    self.class[maxc] = minc
  def __getitem__(self, x):
    return self.whichclass(x)
  
N, M = map(int, input().split())
UF = UnionFind(N)
for i in range(M):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  UF.union(a, b)
count = [0 for i in range(N)]
for i in range(N):
  count[UF[i]] = 1
print(sum(count)-1)
Problem p02556 (python)

Fixed submission:
X = []
Y = []
N = int(input())
for i in range(N):
  x, y = map(int, input().split())
  X.append(x + y)
  Y.append(x - y)

ans = max(max(X)-min(X), max(Y)-min(Y))
print(ans)

Buggy submission (verdict: Runtime Error):
X = []
Y = []
maxX = 0
minX = 10**9
maxY = 0
minY = 10**9

minxy =  float("inf")
maxxy =  -float("inf")
minnxy = float("inf")
maxnnx = -float("inf")
N = int(input())
for i in range(N):
  x, y = map(int, input().split())
  minxy = min(minxy, y-x)
  maxxy = min(maxxy, y-x)
  minnxy = min(minnxy, x + y)
  maxnxy = max(maxnxy, x + y)
  X.append(x)
  Y.append(y)
  maxX, minX = max(maxX, x), min(minX, x)
  maxY, minY = max(maxY, y), min(minY, y)
maxXmaxY = 0
maxXminY = 10**9
minXmaxY = 0
minXminY = 10**9
maxYmaxX = 0
maxYminX = 10**9
minYmaxX = 0
minYminX = 10**9
for i in range(N):
  if X[i]==maxX:
    maxXmaxY = max(maxXmaxY, Y[i])
    maxXminY = min(maxXminY, Y[i])
  if X[i]==minX:
    minXmaxY = max(minXmaxY, Y[i])
    minXminY = min(minXminY, Y[i])
  if Y[i]==maxY:
    maxYmaxX = max(maxYmaxX, X[i])
    maxYminX = min(maxYminX, X[i])
  if Y[i]==minY:
    minYmaxX = max(minYmaxX, X[i])
    minYminX = min(minYminX, X[i])
ans = maxX - minX  + max(abs(maxXmaxY-minXminY),abs(maxXminY-minXmaxY))
ans = max(ans, maxY - minY  + max(abs(maxYmaxX-minYminX),abs(maxYminX-minYmaxX)))
ans = max(ans, maxYmaxX - minX + maxY - minXminY)
ans = max(ans, maxX - maxYminX + maxY - minXminY)
ans = max(ans, minYmaxX - minX + minXmaxY - minY)
ans = max(ans, maxX - minYminX + maxXmaxY - minY)
ans = max(ans, maxxy-minxy, maxnxy-minnxy)
print(ans)
Problem p02573 (python)

Fixed submission:
from collections import deque
 
N, M = map(int, input().split())
g = {i:set() for i in range(N)}
v = [-1 for i in range(N)]
for _ in range(M):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  g[a].add(b)
  g[b].add(a)
  
Q = deque()
ans = 0
for a in g:
  if v[a]==-1:
    v[a] = 1
    ans_tmp = 1
    Q.append(a)
    while len(Q)>0:
      na = Q.popleft()
      for nb in g[na]:
        if v[nb] == -1:
          v[nb] = 1
          ans_tmp += 1
          Q.append(nb)
    ans = max(ans, ans_tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
r = [i for i in range(N+1)]
n = [0 for i in range(N+1)]
buf = []

def root(x):
  if x==r[x]:
    return x
  else:
    r[x] = root(r[x])
    return r[x]

def unite(x, y):
  rx = root(x)
  ry = root(y)
  if rx != ry:
    r[ry] = rx

for _ in range(M):
  a, b = map(int, input().split())
  unite(a, b)

for x in range(1, N+1):
  if r[x] != x and r[r[x]] != r[x]:
    _ = root(x)
  
  
for x in r[1:]:
  n[x] += 1
    
ans = max(n[1:])

print(ans)
Problem p02574 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
B = [0 for i in range(max(A)+1)]
 
for i in range(2, len(B)):
  if B[i] != 0:
    continue
  for j in range(i, len(B), i):
    B[j] = i

def func(X):
  buf = set()
  while X>1:
    x = B[X]
    buf.add(x)
    while X%x==0:
      X = X//x
  #print(buf)
  return buf
 
set1 = func(A[0])
set2 = func(A[0])
totallen = len(set1)
for a in A[1:]:
  set3 = func(a)
  totallen += len(set3)
  #print(a, set1, set2)
  set1 |= set3
  set2 &= set3
  #print(set1, set2, set3)
#print(totallen, set1, set2)
if len(set2)!=0:
  print("not coprime")
elif len(set1)==totallen:
  print("pairwise coprime")
else:
  print("setwise coprime")

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

B = [0 for i in range(max(A)+1)]

for i in range(2, len(B)):
  if B[i] != -1:
    continue
  for j in range(i, len(B), i):
    B[j] = i

def func(X):
  buf = set()
  while X>1:
    x = B[X]
    buf.add(x)
    while X%x==0:
      X = X//x
  return buf

set1 = func(A[0])
set2 = set(set1)
totallen = len(set1)
for a in A[1:]:
  set3 = func(a)
  totallen += len(set3)
  set1.union(set3)
  set2.intersection(set3)
if len(set2)==0:
  print("not coprime")
elif len(set1)==totallen:
  print("pairwise coprime")
else:
  print("setwise coprime")
Problem p02576 (python)

Fixed submission:
N, X, T = map(int, input().split())
print(((N-1)//X + 1)*T)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
ch, cw =  map(int, input().split())
gh, gw =  map(int, input().split())
 
f = [[s=="." for s in input()] for h in range(H)]
ans = [[-1 for w in range(W)]for h in range(H)]
 
nextQ = [(ch-1)*1000 + cw-1]
ans[ch-1][cw-1] = 0
while len(nextQ)>0:
  Q = list(nextQ)
  nextQ = set()
  i = 0
  while i<len(Q):
    nh = Q[i]
    i += 1
    nw = nh%1000
    nh = nh//1000
    for dh in range(0-min(nh,2), 3):
      if nh+dh>=H:
        break
      for dw in range(0-min(nw,2), 3):
        if nw + dw>=W:
          break
        if dh==0 and dw==0:
          continue
        if dh*dw==0 and (abs(dh)==1 or abs(dw)==1):
          if ans[nh+dh][nw+dw]==-1:
            if f[nh+dh][nw+dw]:
              Q.append((nh+dh)*1000 + nw+dw)
              ans[nh+dh][nw+dw]=ans[nh][nw]
            else:
              ans[nh+dh][nw+dw]=-2
          elif ans[nh+dh][nw+dw]>ans[nh][nw]:
            Q.append((nh+dh)*1000 + nw+dw)
            nextQ -= {(nh+dh)*1000 + nw+dw}
            ans[nh+dh][nw+dw]=ans[nh][nw]
        else:
          if ans[nh+dh][nw+dw]==-1:
            if f[nh+dh][nw+dw]:
              nextQ.add((nh+dh)*1000 + nw+dw)
              ans[nh+dh][nw+dw]=ans[nh][nw]+1
            else:
              ans[nh+dh][nw+dw]=-2
 
print(ans[gh-1][gw-1])
Problem p02579 (python)

Fixed submission:
H, W = map(int, input().split())
ch, cw =  map(int, input().split())
gh, gw =  map(int, input().split())

f = [[s=="." for s in input()] for h in range(H)]
ans = [[-1 for w in range(W)]for h in range(H)]

nextQ = [(ch-1)*1000 + cw-1]
ans[ch-1][cw-1] = 0
while len(nextQ)>0:
  Q = list(nextQ)
  nextQ = set()
  visited = set()
  while len(Q):
    nh = Q.pop(0)
    nw = nh%1000
    nh = nh//1000
    for dh in range(0-min(nh,2), 3):
      if nh+dh>=H:
        break
      for dw in range(0-min(nw,2), 3):
        if nw + dw>=W:
          break
        if dh==0 and dw==0:
          continue
        if dh*dw==0 and (abs(dh)==1 or abs(dw)==1):
          if ans[nh+dh][nw+dw]==-1:
            if f[nh+dh][nw+dw]:
              Q.append((nh+dh)*1000 + nw+dw)
              visited.add((nh+dh)*1000 + nw+dw)
              ans[nh+dh][nw+dw]=ans[nh][nw]
            else:
              ans[nh+dh][nw+dw]=-2
          elif ans[nh+dh][nw+dw]>ans[nh][nw]:
            Q.append((nh+dh)*1000 + nw+dw)
            visited.add((nh+dh)*1000 + nw+dw)
            ans[nh+dh][nw+dw]=ans[nh][nw]
        else:
          if ans[nh+dh][nw+dw]==-1:
            if f[nh+dh][nw+dw]:
              nextQ.add((nh+dh)*1000 + nw+dw)
              ans[nh+dh][nw+dw]=ans[nh][nw]+1
            else:
              ans[nh+dh][nw+dw]=-2
          elif ans[nh+dh][nw+dw]>ans[nh][nw]:
            nextQ.add((nh+dh)*1000 + nw+dw)
            ans[nh+dh][nw+dw]=ans[nh][nw]+1
  nextQ -= visited
print(ans[gh-1][gw-1])

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
f = [[s=="." for s in input()] for _ in range(H)]

visit = [[-1 for w in range(W)] for h in range(H)]

ch, cw = ch - 1, cw - 1
dh, dw = dh - 1, dw - 1

Q = deque([ch*1000 + cw])
visit[ch][cw] = 0

while len(Q)>0:
  hw = Q.popleft()
  h = hw // 1000
  w = hw % 1000
  for dy in range(-min(2,h), min(3, H-1-h)):
    for dx in range(-min(2,w), min(3, W-1-w)):
      if dx==0 and dy==0:
        continue
      nh = h + dy
      nw = w + dx
      if (dx==0 and abs(dy)==1) or (dy==0 and abs(dx)==1):
        if f[nh][nw]:
          if visit[nh][nw] == -1:
            visit[nh][nw] = visit[h][w]
            Q.appendleft(nh*1000+nw)
          elif visit[nh][nw] > visit[h][w]:
            visit[nh][nw] = visit[h][w]
      else:
        if f[nh][nw]:
          if visit[nh][nw] == -1:
            visit[nh][nw] = visit[h][w] + 1
            Q.append(nh*1000+nw)

print(visit[dh][dw])
Problem p02609 (python)

Fixed submission:
### 解答
def popcount(X):
  pc = 0
  while X>0:
    pc += X%2
    X = X//2
  return pc

N = int(input())
B = input()
X = int(B, 2)

pcx = popcount(X)
pc0to1 = pcx + 1
pc1to0 = pcx - 1
if pc0to1 > 0:
  r0to1 = X%pc0to1
  r20to1 = [1]
  for i in range(1,N):
    r20to1.append((r20to1[-1]*2)%pc0to1)
if pc1to0 > 0:
  r1to0 = X%pc1to0
  r21to0 = [1]
  for i in range(1,N):
    r21to0.append((r21to0[-1]*2)%pc1to0)

for i in range(N):
  b = B[i]
  if b == "0":
    pc = pc0to1
  else:
    pc = pc1to0
  if pc == 0:
    print(0)
    continue

  if b == "0":
    x = r0to1 + r20to1[-(i+1)]
  else:
    x = r1to0 - r21to0[-(i+1)]
  x = x%pc

  ans = 1
  while x > 0:
    pc = popcount(x)
    x = x%pc
    ans += 1
  print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
X = int(input(),2)
 
def f(x, n):
  c = format(x, 'b').count("1")
  if x%c==0:
    return n+1
  else:
    return f(x%c, n + 1)
 
for i in range(N):
  print(f(X^(2**(N-1-i)),0))

Buggy submission (verdict: Runtime Error):
N = int(input())
X = int(input(),2)

def f(x, n):
  c = format(x, 'b').count("1")
  if x%c==0:
    return n+1
  else:
    return f(x%c, n + 1)

for i in range(N):
  print(f(X^(2**(N-1-i)),0))
Problem p02615 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A.sort()
A = A[::-1]
ans = A[0]
for i in range(N-2):
  ans += A[1 + i//2]
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

A.sort(reversed=True)
ans = 0
for i in range(N-1):
  ans += A[(i+1)//2]

print(ans)
Problem p02621 (python)

Fixed submission:
a= int(input())
print(a + (a**2) + (a**3))

Buggy submission (verdict: Runtime Error):
a= int(input())
print(a + (a**2) + (a***3))
Problem p02631 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
 
XOR = 0
for a in A:
  XOR ^= a
for i in range(N):
  A[i] = A[i]^XOR
print(*A)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = map(int, input().split())

XOR = 0
for a in A:
  XOR ^= a
for i in range(N):
  A[i] = A[i]^XOR
print(*A)
Problem p02645 (python)

Fixed submission:
s=input()
print(s[:3])

Buggy submission (verdict: Runtime Error):
### 解答
N, K = map(int, input().split())
A = list(map(int, input().split()))

#B = [0]*N                                 # 記録用のリスト

for k in range(K):                        # 以降の操作をK回繰り返す
  B = [0]*N 
  for i in range(N):                      # 各電球によって照らされる範囲を考える
    start = max(0, i-A[i])                # 始点のインデックスは0かi-A[i]
    end = min(N, i+A[i]+1)                # 終点のインデックスはNかi+A[i]+1
    B[start] += 1                         # 始点に+1を記録する
    if end <= N - 1:
      B[end] -= 1                         # 終点に電球が存在する場合は-1を記録する
  bmin = B[0] 
  for i in range(1, N):                   # 累積和の計算
    B[i] = B[i-1] + B[i]
    bmin = min(B[i], bmin)
  A = B                                   # AをBで更新してつぎのループへ 
  if bmin == N:                        # すべての電球がN個の電球に照らされるタイミングでbreakする
    break

print(*A)                                 # リストAの中身を順に表示
Problem p02657 (python)

Fixed submission:
x,y = map(int, input().split())
print(x*y)

Buggy submission (verdict: Runtime Error):
N, S = map(int, input().split())
A = list(map(int, input().split()))

dp = [[{} for i in range(S+1) ] for j in range(N+1)]
dp[0][0][0]=1
#print(dp)
for i in range(1,N+1):
  #print(i)
  a = A[i-1]
  if i==0:
    if a <= S:
      dp[i][a][1] = 1  
    continue
  for j in range(S+1):
    if len(dp[i-1][j])>0:
      for key, value in dp[i-1][j].items():
        dp[i][j][key] = value
    if j>=a:
      if len(dp[i-1][j-a]) > 0:
        for key, value in dp[i-1][j-a].items():
          if (key+1) in dp[i][j]:
            dp[i][j][key+1] += value
          else:
            dp[i][j][key+1] = value
last = dp[-1][-1]
ans = 0
for key, value in last.items():
  ans += 2**(N-key) * value
  ans %= 998244353
#print(last)
print(ans)
Problem p02658 (python)

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

A.sort()
ans = 1
flag=False
for a in A:
  ans *= a
  if ans > 1e18:
    flag=True
    break
if flag:
  print(-1)
else:
  print(ans)

Buggy submission (verdict: Runtime Error):
x, y = input().split()
x = int(x)
y = int(y.replace(".", ""))
print((x*y)//100)
Problem p02663 (python)

Fixed submission:
H1, M1, H2, M2, K = map(int, input().split())
ans = (H2*60 + M2) - (H1*60 + M1) - K
print(ans)

Buggy submission (verdict: Runtime Error):
def step(n, lis):
  return [l+n for l in lis]

def func(lis):
  if len(lis)==0:
    return -1
  maxval = max(lis)
  lis.pop(lis.index(maxval))
  if maxval==2:
    lis.append(1)
  if maxval>2:
    lis.append(maxval-1)
    lis.append(maxval-2)
  lis.sort()
  lis = lis[:maxA]
  return maxval
N = int(input())
A = list(map(int, input().split()))
maxA = max(A)

lis = [0]
count = 0
ans = 0
flag=False
for i in range(N+1):
  count += 1
  if flag:
    break
  if A[i]==0:
    continue
  lis = step(count, lis)
  count=0
  a = A[i]
  #print(i,lis)
  for j in range(a):
    
    res = func(lis)
    #print(i, res, lis)
    if res == -1:
      flag=True
      break
    else:
      ans += res
  
if flag:
  print(-1)
else:
  print(ans)
Problem p02675 (python)

Fixed submission:
x = input()[-1]
 
if x in ["2","4","5","7","9"]:
  print("hon")
elif x in ["0","1","6","8"]:
  print("pon")
else:
  print("bon")

Buggy submission (verdict: Runtime Error):
import queue

q = queue.Queue()
N, M = map(int, input().split())

ans = [-1 for i in range(N+1)]
path = [[] for i in range(N+1)]

for i in range(M):
  A, B = map(int, input().split())
  path[A].append(B)
  path[B].append(A)
q.put(1)
COUNTER = 0
while not q.empty() :
  now = q.get()
  for p in path[now]:
    if ans[p]==-1:
      ans[p]=now
      q.put(p)
      #print(COUNTER, now,p)
      COUNTER+=1
      
print("Yes")
for i in ans[2:]:
  print(i)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

ans = [-1 for i in range(N-1)]
path = [[] for i in range(N)]

for i in range(M):
  A, B = map(int, input().split())
  path[A-1].append(B)
  path[B-1].append(A)
nows = [1]
COUNTER = 0
while len(nows)>0 :
  buf = []
  for now in nows:
    for p in path[now-1]:
      if ans[p-2]==-1:
        ans[p-2]=now
        buf.append(p)
        #print(COUNTER)
        COUNTER+=1
  nows = buf
  
print("Yes")
for i in ans:
  print(i)
Problem p02678 (python)

Fixed submission:
import queue

q = queue.Queue()
N, M = map(int, input().split())

ans = [-1 for i in range(N+1)]
path = [[] for i in range(N+1)]

for i in range(M):
  A, B = map(int, input().split())
  path[A].append(B)
  path[B].append(A)
q.put(1)
COUNTER = 0
while not q.empty() :
  now = q.get()
  for p in path[now]:
    if ans[p]==-1:
      ans[p]=now
      q.put(p)
      #print(COUNTER, now,p)
      COUNTER+=1
      
print("Yes")
for i in ans[2:]:
  print(i)

Buggy submission (verdict: Runtime Error):
def saiki(visited, inv, path, nows):
  buf = []
  for now in nows:
    for p in path[now]:
      if p not in visited:
        buf.append(p)
        visited.append(p)
        inv[p-2]=now
  if len(buf)==0:
    return
  saiki(visited, inv, path, buf)
  
N, M = map(int, input().split())

inv = [i for i in range(N-1)]
visited = [1]

path = {i :[] for i in range(1, N+1)}
for i in range(M):
  A, B = map(int, input().split())
  path[A].append(B)
  path[B].append(A)
saiki(visited, inv, path, [1])
print("Yes")
for i in inv:
  print(i)

Buggy submission (verdict: Runtime Error):
def saiki(visited, inv, path, nows):
  buf = []
  for now in nows:
    for p in path[now]:
      if p not in visited:
        buf.append(p)
        visited.append(p)
        inv[p].append(now)
  if len(buf)==0:
    return
  saiki(visited, inv, path, buf)
  
N, M = map(int, input().split())

inv = {i :[] for i in range(2, N+1)}
visited = [1]

path = {i :[] for i in range(1, N+1)}
for i in range(M):
  A, B = map(int, input().split())
  path[A].append(B)
  path[B].append(A)
saiki(visited, inv, path, [1])
print("yes")
for _,i in inv.items():
  print(i[0])