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

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

e = {i: [] for i in range(N)}
for _ in range(M):
  a, b = [int(x)-1 for x in input().split(" ")]
  e[a] = e[a] + [b]
  e[b] = e[b] + [a]

d = np.ones(N, dtype=int) * -1
q = [0]
while len(q) != 0:
  v = q.pop(0)
  for ne in e[v]:
    if d[ne] == -1:
      d[ne] = v
      q.append(ne)

print("Yes")
# for p in prev[1:]:
#   print(p+1)
# print("\n".join([str(p+1) for p in d[1:]]))
for p in d[1:]:
  print(p+1)


Fixed submission:
import numpy as np
N, M = map(int, input().split(" "))

goto = {i: [] for i in range(1, N+1)}
sign = np.zeros(N, dtype=int)
for _ in range(M):
  A, B = map(int, input().split(" "))
  goto[A].append(B)
  goto[B].append(A)

# print(goto)

visited = set([1])
queue = [1]
while len(queue) > 0:
  v = queue.pop(0)
  for nex in goto[v]:
    if nex in visited:
      continue
    sign[nex-1] = v
    queue.append(nex)
    visited.add(nex)
print("Yes")
for s in sign[1:]:
  print(s)

Buggy python submission (verdict: Runtime Error):
# import heapq
import numpy as np

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

e = {i: [] for i in range(N)}
for _ in range(M):
  a, b = [int(x)-1 for x in input()]
  e[a].append(b)
  e[b].append(a)

d = np.ones(N, dtype=int) * -1

q = [0]
while len(q) != 0:
  v = q.pop(0)
  for ne in e[v]:
    if d[ne] == -1:
      d[ne] = v
      q.append(ne)

print("Yes")
# for p in prev[1:]:
#   print(p+1)
print("\n".join([str(p+1) for p in d[1:]]))


Fixed submission:
import numpy as np
N, M = map(int, input().split(" "))

goto = {i: [] for i in range(1, N+1)}
sign = np.zeros(N, dtype=int)
for _ in range(M):
  A, B = map(int, input().split(" "))
  goto[A].append(B)
  goto[B].append(A)

# print(goto)

visited = set([1])
queue = [1]
while len(queue) > 0:
  v = queue.pop(0)
  for nex in goto[v]:
    if nex in visited:
      continue
    sign[nex-1] = v
    queue.append(nex)
    visited.add(nex)
print("Yes")
for s in sign[1:]:
  print(s)

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

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

e = {i: [] for i in range(N)}
for _ in range(M):
  a, b = [int(x)-1 for x in input().split(" ")]
  e[a] = e[a] + [b]
  e[b] = e[b] + [a]

# roots = [[int(x) for x in input().split(" ")] for _ in range(M)]

d = np.ones(N, dtype=int) * -1
# prev = np.ones(N, dtype=int) * -1
# q = [(d[0], 0)]
# heapq.heapify(q)

# while len(q) != 0:
#   c, u = heapq.heappop(q)
#   for nv in e[u]:
#     alt = d[u] + 1
#     if d[nv] > alt:
#       d[nv] = alt
#       prev[nv] = u
#       heapq.heappush(q, (alt, nv))

q = [0]
while len(q) != 0:
  v = q.pop(0)
  for ne in e[v]:
    if d[ne] == -1:
      d[ne] = v
      q.append(ne)

print("Yes")
# for p in prev[1:]:
#   print(p+1)
print("\n".join([str(p+1) for p in d[1:]]))


Fixed submission:
import numpy as np
N, M = map(int, input().split(" "))

goto = {i: [] for i in range(1, N+1)}
sign = np.zeros(N, dtype=int)
for _ in range(M):
  A, B = map(int, input().split(" "))
  goto[A].append(B)
  goto[B].append(A)

# print(goto)

visited = set([1])
queue = [1]
while len(queue) > 0:
  v = queue.pop(0)
  for nex in goto[v]:
    if nex in visited:
      continue
    sign[nex-1] = v
    queue.append(nex)
    visited.add(nex)
print("Yes")
for s in sign[1:]:
  print(s)

Buggy python submission (verdict: Runtime Error):
import heapq
import numpy as np

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

e = {i: [] for i in range(N)}
for _ in range(M):
  a, b = [int(x)-1 for x in input().split(" ")]
  e[a] = e[a] + [b]
  e[b] = e[b] + [a]

# roots = [[int(x) for x in input().split(" ")] for _ in range(M)]

d = np.ones(N, dtype=int) * -1
# prev = np.ones(N, dtype=int) * -1
# q = [(d[0], 0)]
# heapq.heapify(q)

# while len(q) != 0:
#   c, u = heapq.heappop(q)
#   for nv in e[u]:
#     alt = d[u] + 1
#     if d[nv] > alt:
#       d[nv] = alt
#       prev[nv] = u
#       heapq.heappush(q, (alt, nv))

q = [d[0]]
while len(q) != 0:
  v = q.pop(0)
  for ne in e[v]:
    if d[ne] == -1:
      d[ne] = v
    q.append(ne)

print("Yes")
# for p in prev[1:]:
#   print(p+1)
print("\n".join([str(p+1) for p in d[1:]]))


Fixed submission:
import numpy as np
N, M = map(int, input().split(" "))

goto = {i: [] for i in range(1, N+1)}
sign = np.zeros(N, dtype=int)
for _ in range(M):
  A, B = map(int, input().split(" "))
  goto[A].append(B)
  goto[B].append(A)

# print(goto)

visited = set([1])
queue = [1]
while len(queue) > 0:
  v = queue.pop(0)
  for nex in goto[v]:
    if nex in visited:
      continue
    sign[nex-1] = v
    queue.append(nex)
    visited.add(nex)
print("Yes")
for s in sign[1:]:
  print(s)

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

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

e = {i: [] for i in range(N)}
for _ in range(M):
  a, b = [int(x)-1 for x in input().split(" ")]
  e[a] = e[a] + [b]
  e[b] = e[b] + [a]

# roots = [[int(x) for x in input().split(" ")] for _ in range(M)]

d = np.ones(N, dtype=int) * np.inf
d[0] = 0
prev = np.ones(N, dtype=int) * -1
q = [(d[0], 0)]
heapq.heapify(q)

while len(q) != 0:
  c, u = heapq.heappop(q)
  for nv in e[u]:
    alt = d[u] + 1
    if d[nv] > alt:
      d[nv] = alt
      prev[nv] = u
      heapq.heappush(q, (alt, nv))

print("Yes")
# for p in prev[1:]:
#   print(p+1)
print("\n".join([str(p+1) for p in prev[1:]]))


Fixed submission:
import numpy as np
N, M = map(int, input().split(" "))

goto = {i: [] for i in range(1, N+1)}
sign = np.zeros(N, dtype=int)
for _ in range(M):
  A, B = map(int, input().split(" "))
  goto[A].append(B)
  goto[B].append(A)

# print(goto)

visited = set([1])
queue = [1]
while len(queue) > 0:
  v = queue.pop(0)
  for nex in goto[v]:
    if nex in visited:
      continue
    sign[nex-1] = v
    queue.append(nex)
    visited.add(nex)
print("Yes")
for s in sign[1:]:
  print(s)

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

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

e = {i: [] for i in range(N)}
for _ in range(M):
  a, b = [int(x)-1 for x in input().split(" ")]
  e[a] = e[a] + [b]
  e[b] = e[b] + [a]

# roots = [[int(x) for x in input().split(" ")] for _ in range(M)]

d = np.ones(N, dtype=int) * np.inf
d[0] = 0
prev = np.ones(N, dtype=int) * -1
q = [(d[0], 0)]
heapq.heapify(q)

while len(q) != 0:
  c, u = heapq.heappop(q)
  for nv in e[u]:
    alt = d[u] + 1
    if d[nv] > alt:
      d[nv] = alt
      prev[nv] = u
      heapq.heappush(q, (alt, nv))

print("Yes")
for p in prev[1:]:
  print(p+1)


Fixed submission:
import numpy as np
N, M = map(int, input().split(" "))

goto = {i: [] for i in range(1, N+1)}
sign = np.zeros(N, dtype=int)
for _ in range(M):
  A, B = map(int, input().split(" "))
  goto[A].append(B)
  goto[B].append(A)

# print(goto)

visited = set([1])
queue = [1]
while len(queue) > 0:
  v = queue.pop(0)
  for nex in goto[v]:
    if nex in visited:
      continue
    sign[nex-1] = v
    queue.append(nex)
    visited.add(nex)
print("Yes")
for s in sign[1:]:
  print(s)