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

Fixed submission:
s = input()

if s == 'a' or s == 'i' or s == 'u' or s == 'e' or s == 'o':
  ans = 'vowel'
else:
  ans = 'consonant'

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()

if s == 'a' or s == 'i' or s == 'u' or s == 'e' or s == 'o':
  ans = 'vowel'
else:
  ans = 'consonant"

print(ans)
Problem p03943 (python)

Fixed submission:
a, b, c = map(int, input().split())

num_lists = [a, b, c]
maximum = a
if maximum < b: maximum = b
if maximum < c: maximum = c

max_index = num_lists.index(maximum)
num_lists.pop(max_index)

remainder = num_lists[0] + num_lists[1]
if maximum == remainder:
  ans = 'Yes'
else:
  ans = 'No'
  
print(ans)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

num_lists = [a, b, c]
maximum = a
if a == b or a == c or b == c:
  ans = 'No'
else:
  if maximum < b:
    maximum = b
  if maximum < c:
    maximum = c

num_lists.remove(maximum)
if num_lists[0] + num_lists[1] == maximum:
  ans ='Yes'

print(ans)
Problem p04029 (python)

Fixed submission:
n = int(input())

ans = int(n * (1 + n) / 2)
print(ans)

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

ans = n(1+n)/2
print(ans)
Problem p02584 (python)

Fixed submission:
x,k,d = map(int, input().split())
x = abs(x)

walk = min(k,x//d)
k -= walk
x -= walk*d

if k%2 == 0:
    print(x)
else:
    print(d-x)

Buggy submission (verdict: Runtime Error):
x,k,d = map(int, input().split())

walk = min(k,x//d)
k -= walk

x = abs(x)

if x > 0:
    x -= walk*d

    if abs(x - d) < x and k > 0:
        k -= 1
        x -= d

    if k % 2 == 0:
        ans = abs(x)
    else:
        ans = min(abs(x-d),abs(x+d))

print(ans)
Problem p02705 (python)

Fixed submission:
print(int(input()) * 2 * 3.141)

Buggy submission (verdict: Runtime Error):
N = int(input())
a_list = list(map(int, input().split()))
a_list = [ (i+2, s) for i, s in enumerate(a_list) ]
a_list = sorted(a_list, key=lambda x: x[1])
count = 0
boss = 1
for a in a_list:
    if a[1] == boss:
        count += 1
    else:
        diff = a[1] - boss
        for _ in range(diff):
            print(count)
            count = 0
        boss = a[1]
        count += 1

for _ in range(N - a_list[-1][1]+1):
    print(count)
    count = 0
Problem p02971 (python)

Fixed submission:
n = int(input())
a_l = [ int(input()) for _ in range(n)]

l = []
r = []
l_max = 0
r_max = 0
for i in range(n):
    l_max = max(l_max, a_l[i])
    r_max = max(r_max, a_l[-i-1])
    l.append(l_max)
    r.append(r_max)
for i in range(n):
    if i == 0:
        t_l = 0
    else:
        t_l = l[i-1]
    if i == n-1:
        t_r = 0
    else:
        t_r = r[-i-2]
    print(max([t_l,t_r]))

Buggy submission (verdict: Runtime Error):
a_l = [ int(input()) for _ in range(n)]

l = []
r = []
l_max = 0
r_max = 0
for i in range(n):
    l_max = max(l_max, a_l[i])
    r_max = max(r_max, a_l[-i-1])
    l.append(l_max)
    r.append(r_max)
for i in range(n):
    if i == 0:
        t_l = 0
    else:
        t_l = l[i-1]
    if i == n-1:
        t_r = 0
    else:
        t_r = r[-i-2]
    print(max([t_l,t_r]))

Buggy submission (verdict: Runtime Error):
a_l = [ int(input()) for _ in range(n)]


l = []
r = []
l_max = 0
r_max = 0
for i in range(n):
    l_max = max(l_max, a_l[i])
    r_max = max(r_max, a_l[-i-1])
    l.append(l_max)
    r.append(r_max)
for i in range(n):
    if i == 0:
        t_l = 0
    else:
        t_l = l[i-1]
    if i == n-1:
        t_r = 0
    else:
        t_r = r[-i-2]
    print(max([t_l,t_r]))
Problem p03238 (python)

Fixed submission:
N = int(input())
if N == 1:
    print('Hello World')
else:
    A = int(input())
    B = int(input())
    print(A + B)

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
i = 0
min_cost = 1000
fg = False
while i < N:
    i += 1
    c, t = map(int, input().split())
    if t <= T:
        if c <= min_cost:
            fg = True
            min_cost = c

if fg:
    print(min_cost)
else:
    print('TLE')

Buggy submission (verdict: Runtime Error):
N = input()
if N == 1:
    print('Hello World')
else:
    A = int(input())
    B = int(input())
    print(A + B)
Problem p03262 (python)

Fixed submission:
from functools import reduce

N, X = map(int, input().split())

def _calc(a,b):
    while b:
        a, b = b, a % b
    return a

def calc(n_list):
    return reduce(_calc, n_list)

c = list(map(int, input().split()))
c = [ abs(x-X) for x in c ]

print(calc(c))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

def calc(n_list):
    return reduce(math.gcd, n_list)

N, X = map(int, input().split())
c = list(map(int, input().split()))
c = [ abs(x-X) for x in c ]

print(calc(c))
Problem p03282 (python)

Fixed submission:
s = input()
k = int(input())

if k == 1 or len(s) == 1:
    ans = list(s)[0]
else:
    ans = None
    for i, j in enumerate(list(s)):
        if i < k-1:
            if j != '1':
                ans = j
                break
        elif i == k-1:
            ans = j           
            break
        else:
            continue
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

if k == 1 or len(s) == 1:
    ans = list(s)[0]
else:
    for i, j in enumerate(list(s)):
        if j != '1' and i < k:
            ans = j
            break
        elif i >=k :
            ans = '1'
            break
        else:
            continue
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())

if k == 1:
    ans = list(s)[0]
else:
    for i, j in enumerate(list(s)):
        if j != '1' and i < k:
            ans = j
            break
        elif i >=k :
            ans = '1'
            break
        else:
            continue
print(ans)
Problem p03355 (python)

Fixed submission:
s = input()
k = int(input())
ans = set()
r = len(s)

if r == 1:
    print(s)
else:
    for i in range(r):
        for j in range(k):
            ans.add(s[i:i+j+1])
    print(sorted(list(ans))[k-1])

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
ans = set()
r = len(s)
if r <= 50:
    for i in range(r):
        for j in range(r):
            ans.add(s[i:r-j])
    print(sorted(list(ans))[k])
else:
    print('Pass')

Buggy submission (verdict: Runtime Error):
s = input()
k = int(input())
ans = set()
r = len(s)
for i in range(r):
    for j in range(r):
        ans.add(s[i:r-j+1])
print(sorted(list(ans))[k])
Problem p03361 (python)

Fixed submission:
H, W = map(int, input().split())
s_a = []
for _ in range(H):
    s = list(input())
    s_a.append(s)

check_list = [(0,1),(0,-1),(1,0),(-1,0)]

def check(i,j):
    for x,y in check_list:
        try: 
            if s_a[i+x][j+y] == '#':
                return True
        except:
            continue
    return False

ans = 'Yes'
for i in range(H):
    for j in range(W):
        if s_a[i][j] == '#':
            if check(i,j):
                continue
            else:
                ans = 'No'
                break
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s_a = []
for _ in range(W):
    s = list(input())
    s_a.append(s)

check_list = [(0,1),(0,-1),(1,0),(-1,0)]

def check(i,j):
    for x,y in check_list:
        try: 
            if s_a[i+x][j+y] == '#':
                return True
        except:
            continue
    return False

ans = 'Yes'
for i in range(W):
    for j in range(H):
        if s_a[i][j] == '#':
            if check(i,j):
                continue
            else:
                ans = 'No'
                break
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s_a = []
for _ in range(W):
    s = list(input())
    s_a.append(s)

check_list = [(0,1),(0,-1),(1,0),(-1,0)]

def check(i,j):
    for x,y in check_list:
        try: 
            if s_a[i+x][j+y] == '#':
                return True
        except:
            continue
    return False

ans = 'Yes'
for i in range(W):
    for j in range(H):
        if s_a[i][j] == '#':
            if check(i,j):
                continue
            else:
                ans = 'No'
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s_a = []
for _ in range(W):
    s = list(input())
    s_a.append(s)

check_list = [(0,1),(0,-1),(1,0),(-1,0)]

def check(i,j):
    for x,y in check_list:
        try: 
            if s_a[i+x][j+y] == '#':
                return True
        except:
            continue
    return False

ans = 'Yes'
for i in range(H):
    for j in range(W):
        if s_a[i][j] == '#':
            if check(i,j):
                continue
            else:
                ans = 'No'
print(ans)
Problem p03556 (python)

Fixed submission:
n = int(input())
import math
print(int(math.sqrt(n))**2)

Buggy submission (verdict: Runtime Error):
n = int(input())
import math
print(int(math.sqrt(n))
Problem p03738 (python)

Fixed submission:
a = int(input())
b = int(input())
if a > b:
    print('GREATER')
elif a < b:
    print('LESS')
else:
    print('EQUAL')

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a > b:
    print('GREATER')
elif a < n:
    print('LESS')
else:
    print('EQUAL')
Problem p03937 (python)

Fixed submission:
h, w = map(int, input().split())
mat_a = [ list(input()) for _ in range(h) ]

count = 0

ans = True
for i in range(h):
    for j in range(w):
        if mat_a[i][j] == '#':
            count+= 1

if count == h+w-1:
    print('Possible')
else:
    print('Impossible')

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
mat_a = [ list(input()) for _ in range(h) ]


ans = 'Possible'
ans = 'Impossible'

def check(i,j):
    if mat_a[i][j] == '.':
        return True

    count = 0
    try:
        if mat_a[i][j-1] == '#':
            count += 1
    except:
        pass

    try:
        if mat_a[i-1][j] == '#':
            count += 1
    except:
        pass

    try:
        if mat_a[i][j+1] == '#':
            count += 1
    except:
        pass

    try:
        if mat_a[i+1][j] == '#':
            count += 1
    except:
        pass

    if count == 2 or count ==4:
        return True
    else:
        return False    


ans = True
for i in range(h):
    for j in range(w):
        if not check(i,j):
            if i+1 == h and j+1 == w:
                continue
            if i == 0 and j == 0:
                continue
            ans = False
            break

if ans:
    print('Possible')
else:
    print('Impossible')
(env3) (kentaro:~/git/2020/atcode/20200717/3 2020-07-17T17:09:31)$ vi main.py 
(env3) (kentaro:~/git/2020/atcode/20200717/3 2020-07-17T17:10:52)$ cat main.py 
h, w = map(int, input().split())
mat_a = [ list(input()) for _ in range(h) ]

def check(i,j):
    if mat_a[i][j] == '.':
        return True

    count = 0
    try:
        if mat_a[i][j-1] == '#':
            count += 1
    except:
        pass

    try:
        if mat_a[i-1][j] == '#':
            count += 1
    except:
        pass

    try:
        if mat_a[i][j+1] == '#':
            count += 1
    except:
        pass

    try:
        if mat_a[i+1][j] == '#':
            count += 1
    except:
        pass

    if count == 2 or count == 4:
        return True
    else:
        return False    


ans = True
for i in range(h):
    for j in range(w):
        if not check(i,j):
            if i+1 == h and j+1 == w:
                continue
            if i == 0 and j == 0:
                continue
            ans = False
            break

if ans:
    print('Possible')
else:
    print('Impossible')
Problem p04032 (python)

Fixed submission:
import sys
S = list(input())
if len(S) == 2 and S[0] == S[1]:
    print("%d %d" % (1, 2))
    sys.exit()

for i in range(len(S) - 2):
    subset = S[i:i+3]
    if subset[0] == subset[2] or subset[1] == subset[2]:
        print("%d %d" % (i+1, i+3))    
        sys.exit()

print("-1 -1")

Buggy submission (verdict: Runtime Error):
S = list(input())

for i,c in enumerate(S):
    if len(S[i:]) == 2:
        subset = S[i:i+1]
        if subset[0] == subset[1]:
            print("%d %d" % (i+1, i+2))
            break   
        continue    
        
    elif len(S[i:]) > 2:
        subset = S[i:i+3]
        if subset[0] in subset[1:] or subset[1] == subset[2]:
            print("%d %d" % (i+1, i+3))    
            break
        continue   

    else:
        print("-1 -1")
Problem p02573 (python)

Fixed submission:
#coding: utf-8
from collections import defaultdict, deque

N, M = [int(x) for x in input().split()]

G = defaultdict(set)
for i in range(M):
    a, b = [int(x) - 1 for x in input().split()]
    G[a].add(b)
    G[b].add(a)

grp = [-1] * N

for i in range(N):
    q = deque()
    q.append((i,i))

    while(len(q) != 0):
        node, color = q.popleft()
        if grp[node] != -1:
            continue
        grp[node] = color
        for n in G[node]:
            if grp[n] == -1:
                q.append((n, color))

n = defaultdict(int)
for i in range(N):
    n[grp[i]] += 1

ret = 0
for r in n:
    ret = max(ret, n[r])
print(ret)

Buggy submission (verdict: Runtime Error):
#coding: utf-8
from collections import defaultdict

N, M = [int(x) for x in input().split()]

G = defaultdict(set)
for i in range(M):
    a, b = [int(x) - 1 for x in input().split()]
    G[a].add(b)
    G[b].add(a)

grp = [-1] * N

def dfs(node, color):
    if grp[node] != -1:
        return 
    grp[node] = color
    for n in G[node]:
        if grp[n] == -1:
            dfs(n, color)

for i in range(N):
    dfs(i, i)

n = defaultdict(int)
for i in range(N):
    n[grp[i]] += 1

ret = 0
for r in n:
    ret = max(ret, n[r])
print(ret)
Problem p02802 (python)

Fixed submission:
#coding: utf-8

import bisect
import math

N, M = (int(v) for v in input().split())

seen = {}
WA = {}

acs = 0
was = 0

for i in range(M):
    q, tmp = input().split()
    if tmp == "AC":
        if q not in seen:
            acs += 1
            if q not in WA:
                WA[q] = 0
            was += WA[q]
            seen[q] = 1
    else:
        if q not in WA:
            WA[q] = 1
        else:
            WA[q] += 1

print (acs, was)

Buggy submission (verdict: Runtime Error):
coding: utf-8

import bisect
import math

N, M = (int(v) for v in input().split())

seen = {}
WA = {}

acs = 0
was = 0

for i in range(M):
    q, tmp = input().split()
    if tmp == "AC":
        if q not in seen:
            acs += 1
            if q not in WA:
                WA[q] = 0
            was += WA[q]
            seen[q] = 1
    else:
        if q not in WA:
            WA[q] = 1
        else:
            WA[q] += 1

print (acs, was)
Problem p03044 (python)

Fixed submission:
#coding: utf-8
from collections import defaultdict, deque

N = int(input())
G = {}
for i in range(1, N+1):
    G[i] = []

for i in range(N-1):
    u, v, w = (int(n) for n in input().split())
    G[u].append((v, w))
    G[v].append((u, w))

ret = [-1] * (N+1)

que = deque()
que.append((1, 0))

while len(que) > 0:
    node, distance = que[0]
    que.popleft()

    ret[node] = distance % 2
    for next_node, next_distance in G[node]:
        if ret[next_node] == -1:
            que.append((next_node, distance + next_distance))

for i in range(N):
    print(ret[i+1])

Buggy submission (verdict: Runtime Error):
#coding: utf-8
from collections import defaultdict

N = int(input())
G = {}
for i in range(1, N+1):
    G[i] = []

for i in range(N-1):
    u, v, w = (int(n) for n in input().split())
    G[u].append((v, w))
    G[v].append((u, w))

ret = [-1] * (N)

def dfs(node, d):
    if ret[node-1] != -1:
        return

    if d % 2 == 0:
        ret[node-1] = 0
    else:
        ret[node-1] = 1 

    for next_node in G[node]:
        dfs(next_node[0], d + next_node[1])

dfs(1, 0)
for i in range(N):
    print(ret[i])

Buggy submission (verdict: Runtime Error):
#coding: utf-8
from collections import defaultdict

N = int(input())
G = {}
for i in range(1, N+1):
    G[i] = []

for i in range(N-1):
    u, v, w = (int(n) for n in input().split())
    G[u].append((v, w))
    G[v].append((u, w))

ret = [-1] * (N+1)

def dfs(node, d):
    if ret[node] != -1:
        return

    if d % 2 == 0:
        ret[node] = 0
    else:
        ret[node] = 1 

    for next_node in G[node]:
        dfs(next_node[0], d + next_node[1])

dfs(1, 0)
for i in range(N):
    print(ret[i+1])
Problem p03263 (python)

Fixed submission:
#coding: utf-8
from collections import deque

H, W = (int(x) for x in input().split())
A = []

curMove = []
moves = []
hasOdd = False
pi = -1
pj = -1
for i in range(H):
    row = [int(x) for x in input().split()]
    if i % 2 == 0:
        start, end, diff = 0, W, 1
    else:
        start, end, diff = W-1, 0-1, -1

    for j in range(start, end, diff):
        if row[j] % 2 == 1:
            if hasOdd:
                curMove.append((pi,pj, i, j))
                moves += curMove
                curMove = []
                hasOdd = False
            else:
                hasOdd = True
        else:
            if hasOdd:
                curMove.append((pi,pj, i, j))
        pi = i
        pj = j

print(len(moves))
for m in moves:
    print(" ".join((str(i+1) for i in m)))

Buggy submission (verdict: Runtime Error):
#coding: utf-8
from collections import deque

H, W = (int(x) for x in input().split())
A = []

posOdd = deque() 
i = 0
j = 0

while (i, j) != H-1, W-1:
    if i

for i in range(H):
    row = [int(x) for x in input().split()]
    A.append(row)



def move(src, dst):
    ret = []
    while src[0] != dst[0]:
        if src[0] > dst[0]:
            di = -1
        else:
            di = 1
        ret.append((src[0], src[1], src[0]+di, src[1]))
        src[0] += di 
    return ret

    while src[1] != dst[1]:
        if src[1] > dst[1]:
            dj = -1
        else:
            dj = 1
        ret.append((src[0], src[1], src[0], src[1]+dj))
        src[1] += dj 

moves = []
while len(posOdd) > 1:
    dst = posOdd.popleft()
    src = posOdd.popleft()
    moves += move(src, dst)

print(len(moves))
for m in moves:
    print(" ".join((str(i+1) for i in m)))

Buggy submission (verdict: Runtime Error):
#coding: utf-8
from collections import deque

H, W = (int(x) for x in input().split())
A = []

posOdd = deque() 
for i in range(H):
    row = [int(x) for x in input().split()]
    A.append(row)
    if i % 2 == 0:
        for j in range(W):
            if row[j] % 2 == 1:
                posOdd.append([i, j])
    else:
        for j in reversed(range(W)):
            if row[j] % 2 == 1:
                posOdd.append([i, j])


def move(src, dst):
    ret = []
    while src[1] != dst[1]:
        if src[1] > dst[1]:
            dj = -1
        else:
            dj = 1
        ret.append((src[0], src[1], src[0], src[1]+dj))
        src[1] += dj 

    while src[0] != dst[0]:
        if src[0] > dst[0]:
            di = -1
        else:
            di = 1
        ret.append(src[0], src[1], src[0]+di, src[1])
        src[0] += di 
    return ret

moves = []
while len(posOdd) > 1:
    dst = posOdd.popleft()
    src = posOdd.popleft()
    moves += move(src, dst)

print(len(moves))
for m in moves:
    print(" ".join((str(i+1) for i in m)))
Problem p02612 (python)

Fixed submission:
n=int(input())%1000
print(0 if n==0 else 1000-n)

Buggy submission (verdict: Runtime Error):
n=int(input())%1000
print(n is 0 0 else 1000-n)
Problem p02657 (python)

Fixed submission:
a, b = map(int, input().split())
print(a * b)

Buggy submission (verdict: Runtime Error):
print(int(input()) * int(input()))
Problem p02741 (python)

Fixed submission:
a = [0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input())])

Buggy submission (verdict: Runtime Error):
a = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
     1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
print(a[int(input())])
Problem p03211 (python)

Fixed submission:
S=input()
ans = 111111111
for i in range(2,len(S)):
    temp = abs(753 - (100 * int(S[i - 2]) + 10 * int(S[i - 1]) + int(S[i])))
    ans = min(ans, temp)
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
ans = 111111111
for i in range(2,9):
    temp = abs(753 - (100 * int(S[i - 2]) + 10 * int(S[i - 1]) + int(S[i])))
    ans = min(ans, temp)
print(ans)

Buggy submission (verdict: Runtime Error):
S=input()
ans = 111111111;
for i in range(2,10):
    temp = abs(753 - (100 * int(S[i - 2]) + 10 * int(S[i - 1]) + int(S[i])))
    ans = min(ans, temp)
print(ans)
Problem p03738 (python)

Fixed submission:
a=int(input())
b=int(input())

if a > b:
    print("GREATER")
elif a < b:
    print("LESS")
else:
    print("EQUAL")

Buggy submission (verdict: Runtime Error):
a=input()
b=input()

if a > b:
    printf("GREATER")
elif a < b:
    print("LESS")
else:
    print("EQUAL")
Problem p02657 (python)

Fixed submission:
A, B = list(map(int, input().split()))
print(A*B)

Buggy submission (verdict: Runtime Error):
print(int(input())*int(input()))
Problem p02678 (python)

Fixed submission:
from collections import deque, defaultdict

N, M = map(int, input().split())
outs = defaultdict(list)

for _ in range(M):
    v1, v2 = map(int, input().split())
    #v1, v2 = v1-1,v2-1
    outs[v1].append(v2)
    outs[v2].append(v1)

# print(outs)
q = deque([1])
depth = defaultdict(int)
depth[1] = 0
visit = [False]*N #配列なので0オリジン
visit[0] = True
# print(visit)
while q:
    v1 = q.popleft()
    # print("a",v1)
    for v2 in outs[v1]: #v1のノードから出ている矢印をみる．
        # print("b",v2)
        if visit[v2-1]==False:
            visit[v2-1] = True
            depth[v2] = v1
            q.append(v2)
            # print(v2,q,depth)

b = sorted(depth.items())
# print(b)
print("Yes")
for i in range(1,N):
    print(b[i][1])

Buggy submission (verdict: Runtime Error):
from collections import deque, defaultdict

N, M = map(int, input().split())
outs = defaultdict(list)

for _ in range(M):
    v1, v2 = map(int, input().split())
    # if v1>v2: v1,v2 = v2,v1
    outs[v1].append(v2)
    outs[v2].append(v1)

#print(outs)
q = deque([1])
depth = defaultdict(int)
depth[1] = 0
visit = [False]*M #配列なので0オリジン
visit[0] = True

while q:
    v1 = q.popleft()
    for v2 in outs[v1]: #v1のノードから出ている矢印をみる．
        if visit[v2-1]==False:
            visit[v2-1] = True
            if depth[v2] == 0:
                depth[v2] = v1
            q.append(v2)
            print(v2,q,depth)

b = sorted(depth.items())
#print(b)
print("Yes")
for i in range(1,N):
    print(b[i][1])

Buggy submission (verdict: Runtime Error):
from collections import deque, defaultdict

N, M = map(int, input().split())
outs = defaultdict(list)

for _ in range(M):
    v1, v2 = map(int, input().split())
    # if v1>v2: v1,v2 = v2,v1
    outs[v1].append(v2)
    outs[v2].append(v1)

#print(outs)
q = deque([1])
depth = defaultdict(int)
depth[1] = 0
visit = [False]*M #配列なので0オリジン
visit[0] = True

while q:
    v1 = q.popleft()
    for v2 in outs[v1]: #v1のノードから出ている矢印をみる．
        if visit[v2-1]==False:
            visit[v2-1] = True
            if depth[v2] == 0:
                depth[v2] = depth[v1] + 1
            q.append(v2)
            #print(v2,q,depth)

b = sorted(depth.items())
#print(b)
print("Yes")
for i in range(1,N):
    print(b[i][1])

Buggy submission (verdict: Runtime Error):
from collections import deque, defaultdict

N, M = map(int, input().split())
outs = defaultdict(list)

for _ in range(M):
    v1, v2 = map(int, input().split())
    # if v1>v2: v1,v2 = v2,v1
    outs[v1].append(v2)
    outs[v2].append(v1)

#print(outs)
q = deque([1])
depth = defaultdict(int)
depth[1] = 0
visit = [False]*M #配列なので0オリジン
visit[0] = True

while q:
    v1 = q.popleft()
    for v2 in outs[v1]: #v1のノードから出ている矢印をみる．
        if visit[v2-1]==False:
            visit[v2-1] = True
            if depth[v2] == 0:
                depth[v2] = depth[v1] + 1
            q.append(v2)
            #print(v2,q,depth)

b = sorted(depth.items())
print(b)
print("Yes")
for i in range(1,N):
    print(b[i][1])