Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
nums = [0]*N

for i in range(N):
  nums[A[i]-1] += 1

nums.sort()

while True:
  if nums[0] == 0:
    del nums[0]
  else:
    break

if len(nums) <= K:
  print(0)
else:
  print(sum(nums[:len(nums)-K]))

Fixed submission:
from collections import deque

N,K = map(int,input().split())
A = list(map(int,input().split()))
nums = [0]*N

for i in range(N):
  nums[A[i]-1] += 1

nums.sort()

nums = deque(nums)

while True:
  if nums[0] == 0:
    nums.popleft()
  else:
    break
nums = list(nums)
if len(nums) <= K:
  print(0)
else:
  print(sum(nums[:len(nums)-K]))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
L = len(set(A))
count = []

if L <= K:
  print(0)
else:
  for i in range(1,N+1):
    count.append(A.count(i))
  count.sort(reverse=True)
  print(N-sum(count[:K]))

Fixed submission:
from collections import deque

N,K = map(int,input().split())
A = list(map(int,input().split()))
nums = [0]*N

for i in range(N):
  nums[A[i]-1] += 1

nums.sort()

nums = deque(nums)

while True:
  if nums[0] == 0:
    nums.popleft()
  else:
    break
nums = list(nums)
if len(nums) <= K:
  print(0)
else:
  print(sum(nums[:len(nums)-K]))

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = list(map(int,input().split()))
A_set = set(A)
L = len(A_set)
count = []

if L <= K:
  print(0)
else:
  for i in range(L):
    count.append(A.count(list(A_set)[i]))
  count.sort()
  
  print(sum(count[:len(count)-K]))

Fixed submission:
from collections import deque

N,K = map(int,input().split())
A = list(map(int,input().split()))
nums = [0]*N

for i in range(N):
  nums[A[i]-1] += 1

nums.sort()

nums = deque(nums)

while True:
  if nums[0] == 0:
    nums.popleft()
  else:
    break
nums = list(nums)
if len(nums) <= K:
  print(0)
else:
  print(sum(nums[:len(nums)-K]))
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
ans = 0

for _ in range(N):
  A.append(int(input()))
  
A.sort()

if N == 1:
  print(1)
  
else:
  for i in range(N-2):
    if A[i] != A[i+1]:
      L = len(A[:i+1])
      del A[:i+1]
      if L%2 == 1:
        ans += 1
      
  print(ans)

Fixed submission:
N = int(input())
A = []
count = 1
ans = 0

for _ in range(N):
  A.append(int(input()))

A.sort()

for i in range(N-1):
  if A[i] == A[i+1]:
    count += 1
  else:
    if count%2 == 1:
      ans += 1
    count = 1
else:
  if count%2 == 1:
    ans += 1
  else:
    count = 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = []

for _ in range(N):
  A = int(input())
  if A in As:
    As.remove(A)
  else:
    As.append(A)

print(len(As))

Fixed submission:
N = int(input())
A = []
count = 1
ans = 0

for _ in range(N):
  A.append(int(input()))

A.sort()

for i in range(N-1):
  if A[i] == A[i+1]:
    count += 1
  else:
    if count%2 == 1:
      ans += 1
    count = 1
else:
  if count%2 == 1:
    ans += 1
  else:
    count = 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = []
ans = 0

for _ in range(N):
  A.append(int(input()))
  
S = set(A)

for i in set(A):
  if A.count(i)%2 == 1:
    ans += 1
    
print(ans)

Fixed submission:
N = int(input())
A = []
count = 1
ans = 0

for _ in range(N):
  A.append(int(input()))

A.sort()

for i in range(N-1):
  if A[i] == A[i+1]:
    count += 1
  else:
    if count%2 == 1:
      ans += 1
    count = 1
else:
  if count%2 == 1:
    ans += 1
  else:
    count = 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
ans = 0

for i in range(100000):
  B = [j for j in A if i-1 <= j <= i+1]
  if ans < len(B):
    ans = len(B)
    
print(ans)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
ans = 0
A.sort()
a=0
b=0
c=1

for i in range(N-1):
  if A[i] == A[i+1]:
    a += 1
    b += 1
    c += 1
  elif A[i]+1 == A[i+1]:
    if ans < a:
      ans = a
    a = b
    a += 1
    b = c
    b += 1
    c = 1
  elif A[i]+2 == A[i+1]:
    if ans < a:
      ans = a
    if ans < b:
      ans = b
    a = c
    a += 1
    b = 1
    c = 1
  else:
    if ans < a:
      ans = a
    if ans < b:
      ans = b
    if ans < c:
      ans = c
    a = 1
    b = 1
    c = 1

if ans < a:
      ans = a
if ans < b:
      ans = b
if ans < c:
      ans = c
print(ans)
Buggy python submission (verdict: Runtime Error):
v

Fixed submission:
N = int(input())
ans = 0
for A in map(int, input().split()):
	ans += 1 / A

ans = 1 / ans
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N == 1:
	print("Hello World")
else:
	A, B = map(int, input().split())
	print(A + B)


Fixed submission:
N = int(input())
if N == 1:
	print("Hello World")
else:
	A, B = [int(input()) for i in range(2)]
	print(A + B)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split(' ')))


def min_point(data):
    lgt = len(data)
    m=0
    ins=0
    for i in range(lgt):
        if i ==0:
            buf = min(data[i],data[lgt-1])
        else:
            buf = min(data[i],data[i-1])
        if buf > m:
            m=buf
            ins=i
    return [m,ins]

a.sort(reverse=True)
cnt=0
lst=[]
for i in range(n):
    if i == 0:
        lst.append(a[i])
    elif len(lst) == 1:
        cnt += lst[0]
        lst.append(a[i])
    else:
        mp = min_point(lst)
        cnt += mp[0]
        lst.insert(mp[1], a[i])

print(cnt)

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


a.sort(reverse=True)
cnt=0
for i in range(1,n):
    if i==1:
        cnt+=a[0]
    else:
        j = (i // 2)
        cnt += a[j]
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
cnt = 0
for i in range(1, n+1):
    hoge = int(n//i)
    cnt += (hoge + 1) * i * hoge // 2
print(cnt)

Fixed submission:
n = int(input())
cnt = 0
for i in range(1, n+1):
    hoge = n//i
    cnt += (hoge + 1) * i * hoge / 2
print(int(cnt))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n = int(input())
lst = np.asarray([0] * (n+1))
a = np.array(range(n+1))

for i in range(1,n+1):
    lst += (a % i == 0)

print(sum(lst*a))

Fixed submission:
n = int(input())
cnt = 0
for i in range(1, n+1):
    hoge = n//i
    cnt += (hoge + 1) * i * hoge / 2
print(int(cnt))
Buggy python submission (verdict: Time Limit Exceeded):
import copy


n = int(input())
lst = list(map(int,input().split(' ')))

for i in range(n):
    l = copy.deepcopy(lst)
    del l[i]
    buf = 0
    for ll in l:
        buf ^= ll
    print(buf)

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

x = 0
for l in lst:
    x ^= l
out = ''
for l in lst:
    out += ' ' + str(x^l)
print(out[1:])
Buggy python submission (verdict: Runtime Error):
x,n = map(int,input().split(' '))
p = [int(x) for x in input().split(' ')]

if n == 0:
    print(x)
else:
    s = set([x for x in range(102)])
    s -= set(p)
    for i in range(1,51):
        if x-i in s:
            print(x-i)
            break
        if x+i in s:
            print(x+i)
            break

Fixed submission:
x,n = map(int,input().split(' '))

if n == 0:
    p = input()
    print(x)
else:
    p = [int(x) for x in input().split(' ')]
    s = set([x for x in range(102)])
    s -= set(p)
    for i in range(0,51):
        if x-i in s:
            print(x-i)
            break
        if x+i in s:
            print(x+i)
            break
Buggy python submission (verdict: Time Limit Exceeded):
inputs = input().split(' ')
a = int(inputs[0])
b = int(inputs[1])
n = int(inputs[2]) + 1

output = 0
loop_cnt = n if n < b else b
for x in range(1, loop_cnt):
    buf = (a*x//b)
    if buf > output:
        output = buf

print(output)

Fixed submission:
inputs = input().split(' ')
a = int(inputs[0])
b = int(inputs[1])
n = int(inputs[2]) + 1

x = (n if n < b else b) - 1
output = (a*x//b)

print(output)

Buggy python submission (verdict: Time Limit Exceeded):
inputs = input().split(' ')
a = int(inputs[0])
b = int(inputs[1])
n = int(inputs[2])

output = 0
for x in range(1, n + 1):
    if x % b == 0:
        break
    buf = (a*x//b) - a*(x//b)
    if buf > output:
        output = buf

print(output)

Fixed submission:
inputs = input().split(' ')
a = int(inputs[0])
b = int(inputs[1])
n = int(inputs[2]) + 1

x = (n if n < b else b) - 1
output = (a*x//b)

print(output)

Buggy python submission (verdict: Time Limit Exceeded):
inputs = input().split(' ')
a = int(inputs[0])
b = int(inputs[1])
n = int(inputs[2])

output = 0
ab = a*b
for x in range(1, n + 1):
    if x % ab == 0:
        break
    buf = (a*x//b) - a*(x//b)
    if buf > output:
        output = buf

print(output)

Fixed submission:
inputs = input().split(' ')
a = int(inputs[0])
b = int(inputs[1])
n = int(inputs[2]) + 1

x = (n if n < b else b) - 1
output = (a*x//b)

print(output)

Buggy python submission (verdict: Time Limit Exceeded):
inputs = input().split(' ')
a = int(inputs[0])
b = int(inputs[1])
n = int(inputs[2])

output = 0
for x in range(1, n + 1):
    if x % (a * b) == 0:
        break
    buf = (a*x//b) - a*(x//b)
    if buf > output:
        output = buf

print(output)

Fixed submission:
inputs = input().split(' ')
a = int(inputs[0])
b = int(inputs[1])
n = int(inputs[2]) + 1

x = (n if n < b else b) - 1
output = (a*x//b)

print(output)
Buggy python submission (verdict: Time Limit Exceeded):
member_cnt = int(input())
bosses = input().split(' ')

for i in range(1, member_cnt + 1):
  print(bosses.count(str(i)))

Fixed submission:
import collections


member_cnt = int(input())
bosses = input().split(' ')
boss_dict = collections.Counter(bosses)

for i in range(1, member_cnt + 1):
  print(boss_dict.get(str(i), 0))
Buggy python submission (verdict: Runtime Error):
import math

height, width = [int(i) for i in input().split(' ')]

if height > 1 and width > 2:
    print(math.ceil(width/2) * math.ceil(height/2) + math.floor(width/2) * math.floor(height/2))
else print(1)

Fixed submission:
import math

height, width = [int(i) for i in input().split(' ')]

if height > 1 and width > 2:
    print(math.ceil(width/2) * math.ceil(height/2) + math.floor(width/2) * math.floor(height/2))
else:
    print(1)
Buggy python submission (verdict: Runtime Error):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return True

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())


def main():
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        uf.union(a, b)
    print(uf.group_count() - 1)   

if __name__ == "__main__":
    main()



Fixed submission:
import sys
input = sys.stdin.readline
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        return True

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())


def main():
    n, m = map(int, input().split())
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        uf.union(a, b)
    print(uf.group_count() - 1)   

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353
class ModInt(int):
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return ModInt(self.x + other.x) if isinstance(other, ModInt) else ModInt(self.x + other)

    def __sub__(self, other):
        return ModInt(self.x - other.x) if isinstance(other, ModInt) else ModInt(self.x - other)

    def __mul__(self, other):
        return ModInt(self.x * other.x) if isinstance(other, ModInt) else ModInt(self.x * other)

    def __floordiv__(self, other):
        if isinstance(other, ModInt):
            return ModInt(self.x * pow(other.x, MOD - 2, MOD))
        else:
            if other == 0:
                raise ZeroDivisionError
            else:
                return ModInt(self.x * pow(other, MOD - 2, MOD))

    def __pow__(self, other):
        return ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(self.x, other, MOD))

    __radd__ = __add__

    def __rsub__(self, other):
        return ModInt(other.x - self.x) if isinstance(other, ModInt) else ModInt(other - self.x)

    __rmul__ = __mul__

    def __rfloordiv__(self, other):
        return ModInt(other.x * pow(self.x, MOD - 2, MOD)) if isinstance(other, ModInt) else ModInt(other * pow(self.x, MOD - 2, MOD))

    def __rpow__(self, other):
        return ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else ModInt(pow(other, self.x, MOD))


def main():
    n, k = map(int, input().split())
    L, R = [], []
    for _ in range(k):
        l, r = map(int, input().split())
        L.append(l)
        R.append(r)
    dp = [0] * (n + 1)
    s = [0] * (n + 1)
    dp[1] = ModInt(1)
    s[1] = ModInt(1)
    for i in range(2, n + 1):
        for j in range(k):
            l = max(1, i - R[j])
            r = i - L[j]
            dp[i] += s[r] - s[l - 1]
        s[i] = s[i - 1] + dp[i]
    print(dp[n])


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    MOD = 998244353
    n, k = map(int, input().split())
    L, R = [], []
    for _ in range(k):
        l, r = map(int, input().split())
        L.append(l)
        R.append(r)
    dp = [0] * (n + 1)
    s = [0] * (n + 1)
    dp[1] = 1
    s[1] = 1
    for i in range(2, n + 1):
        for j in range(k):
            l = max(1, i - R[j])
            r = i - L[j]
            if r < 1: continue
            dp[i] += s[r] - s[l - 1]
            dp[i] %= MOD
        s[i] = s[i - 1] + dp[i]
        s[i] %= MOD
    print(dp[n])


if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
def generate_primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def main():  
    n = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    primes = generate_primes(max(A))
    for a in A:
        for p in primes:
            if a < p: break
            if a % p == 0:
                d[p] += 1
    d[1] = 0
    m = max(d.values())
    if m == n:
        print('not coprime')
    elif m >= 2:
        print('setwise coprime')
    else:
        print('pairwise coprime')
    

if __name__ == '__main__':
    main()



Fixed submission:
def main():
    d, t, s = map(int, input().split())  
    print('Yes' if s * t >= d else 'No')

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
def main():
    def f(n):
        if n == 0:
            return 0
        if d[n] != 0:
            return d[n]
        d[n] = f(n % sum(list(map(int, bin(n)[2:])))) + 1
    def rev(i):
        if X[i] == '0':
            print(d[b % (c + 1)] + 1 if (b := (m + (1 << (n - i - 1)))) != 0 else 0)
        else:
            print(d[b % (c - 1)] + 1 if (b := (m - (1 << (n - i - 1)))) != 0 else 0)

    n = int(input())
    X = list(input())
    d = defaultdict(int)
    d[0] = 0
    printl = lambda x, y: print(d[x % y] + 1 if x != 0 else 0)
    for i in range(1, n):
        f(i)
    c = sum(list(map(int, X)))
    m = int(''.join(X), 2)
    for i in range(n):
        rev(i)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    l, r, d = list(map(int, input().split()))
    ans = 0
    for i in range(l, r + 1):
        if i % d == 0:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
def main():
    n = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        B = list(f'{a:030b}')
        for i, b in enumerate(B):
            if b == '1':
                d[i] += 1
    ANS = []
    for a in A:
        B = list(f'{a:030b}')
        ans = 0
        for i, b in enumerate(B):
            if b == '1':
                k = d[i] - 1
            else:
                k = d[i]
            if k % 2 == 1:
                ans += pow(2, 29 - i)
        ANS.append(str(ans))
    print(' '.join(ANS))





if __name__ == '__main__':
    main()


Fixed submission:
from collections import defaultdict
def main():
    n = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A:
        B = list(f'{a:030b}')
        for i, b in enumerate(B):
            if b == '1':
                d[i] += 1
    ANS = []
    for a in A:
        B = list(f'{a:030b}')
        ans = 0
        for i, b in enumerate(B):
            if b == '1':
                k = d[i] - 1
            else:
                k = d[i]
            if k % 2 == 1:
                ans += pow(2, 29 - i)
        ANS.append(str(ans))
    print(' '.join(ANS))





if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
def main():
    n, k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    C = [set(range(n)) for _ in range(n)]
    I = set(range(n))
    if k >= math.log2(n):
        print(' '.join([n] * n))
    else:
        for _ in range(k):
            for i in I:
                rm = set()
                for j in C[i]:
                    if A[j] >= abs(i - j):
                        rm.add(j)
                C[i] -= rm
            if len(C[i]) == 0:
                I.remove(i)
            A = [n - len(C[i]) for i in range(n)]
        print(' '.join(list(map(str, A))))

if __name__ == '__main__':
    main()


Fixed submission:
import numpy as np
from numba import njit
@njit
def op(A, n):
    B = np.zeros_like(A)
    for i, a in enumerate(A[:n]):
        B[max(i - a, 0)] += 1
        B[min(n - 1, a + i) + 1] -= 1
    return np.cumsum(B)

def main():
    n, k = list(map(int, input().split()))
    A = np.array(list(map(int, input().split())) + [0, ], dtype = np.int)
    for _ in range(k):
        A_new = op(A, n)
        if all(A[:n] == A_new[:n]):
            break
        A = A_new
    print(' '.join(list(map(str, A[:n]))))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = list(map(int, input().split()))
    A = list(map(int, input().split()))
    C = [set(range(n)) for _ in range(n)]
    if k >= n:
        print(' '.join([n] * n))
    else:
        for _ in range(k):
            for i in range(n):
                rm = set()
                for j in C[i]:
                    if A[j] >= abs(i - j):
                        rm.add(j)
                C[i] -= rm
            A = [n - len(C[i]) for i in range(n)]
        print(' '.join(list(map(str, A))))


if __name__ == '__main__':
    main()


Fixed submission:
import numpy as np
from numba import njit
@njit
def op(A, n):
    B = np.zeros_like(A)
    for i, a in enumerate(A[:n]):
        B[max(i - a, 0)] += 1
        B[min(n - 1, a + i) + 1] -= 1
    return np.cumsum(B)

def main():
    n, k = list(map(int, input().split()))
    A = np.array(list(map(int, input().split())) + [0, ], dtype = np.int)
    for _ in range(k):
        A_new = op(A, n)
        if all(A[:n] == A_new[:n]):
            break
        A = A_new
    print(' '.join(list(map(str, A[:n]))))

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    ans = 1
    for a in A:
        ans *= a
    if ans <= 10 ** 18:
        print(ans)
    else:
        print(-1)

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n = int(input())
    A = list(map(int, input().split()))
    ans = 1
    x = 10 ** 18
    if 0 in A:
        print(0)
        exit()
    for a in A:
        ans *= a
        if ans > x:
            print(-1)
            exit()
    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n, m = list(map(int, input().split()))
connects = [[0] * n for _ in range(n)]
for _ in range(m):
    i, j = list(map(int, input().split()))
    connects[i - 1][j - 1] = 1
    connects[j - 1][i - 1] = 1
stack = deque([0, ])
visited = [-1] * n
while stack:
    x = stack.popleft()
    connects_with_x = [i for i in range(n) if connects[x][i] == 1]
    for dx in connects_with_x:
        if visited[dx] == -1:
            visited[dx] = x
            stack.append(dx)
        else:
            continue
print('Yes')
[print(i + 1) for i in visited[1:]]

Fixed submission:
from collections import deque
n, m = list(map(int, input().split()))
connects = [[] * n for _ in range(n)]
for _ in range(m):
    i, j = list(map(int, input().split()))
    connects[i - 1].append(j - 1)
    connects[j - 1].append(i - 1)
stack = deque([0, ])
visited = [-1] * n
while stack:
    x = stack.popleft()
    for dx in connects[x]:
        if visited[dx] == -1:
            visited[dx] = x + 1
            stack.append(dx)
        else:
            continue
print('Yes')
[print(i) for i in visited[1:]]

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n, m = list(map(int, input().split()))
connects = [[0] * n for _ in range(n)]
for _ in range(m):
    i, j =  list(map(int, input().split()))
    connects[i - 1][j - 1] = 1
    connects[j - 1][i - 1] = 1
can = False
d = [float('inf')] * n
d[0] = 0
r = [0] * n
visited = [0] * n
stack = deque([0, ])
while stack:
    x = stack.popleft()
    next = [j for j in range(n) if connects[x][j] == 1]
    for dx in next:
        d[dx] = min(d[dx], d[x] + 1)
        if visited[dx]:
            continue
        else:
            stack.append(dx)
            visited[dx] = 1
print('Yes')
for i in range(1, n):
    d_next = [[j + 1, d[j]] for j in range(n) if connects[i][j] == 1]
    d_min = float('inf')
    i_min = 0
    for i, dx in d_next:
        if dx < d_min:
            d_min = dx
            i_min = i
    print(i_min)

Fixed submission:
from collections import deque
n, m = list(map(int, input().split()))
connects = [[] * n for _ in range(n)]
for _ in range(m):
    i, j = list(map(int, input().split()))
    connects[i - 1].append(j - 1)
    connects[j - 1].append(i - 1)
stack = deque([0, ])
visited = [-1] * n
while stack:
    x = stack.popleft()
    for dx in connects[x]:
        if visited[dx] == -1:
            visited[dx] = x + 1
            stack.append(dx)
        else:
            continue
print('Yes')
[print(i) for i in visited[1:]]