Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, M = map(int, input().split())

adj = [[float("inf") for i in range(N)] for j in range(N)]
signs = [-1 for i in range(N)]
not_patrolled = set(range(1, N))

for _ in range(M):
  x,y = map(int,input().split())
  adj[x - 1][y - 1] = 1
  adj[y - 1][x - 1] = 1

queue = deque([0])

while len(queue) > 0:
  cur = queue.popleft()
  for i in not_patrolled.copy():
    c = adj[cur][i]
    if c == 1:
      queue.append(i)
      signs[i] = cur
      not_patrolled.remove(i)

if len(not_patrolled) == 0:
  print("Yes")
  for sign in signs[1:]:
    print(sign + 1)
else:
  print("No")

Fixed submission:
from collections import deque
N, M = map(int, input().split())

adj = [[] for i in range(N)]
signs = [-1 for i in range(N)]
# not_patrolled = set(range(1, N))

for _ in range(M):
  x,y = map(int,input().split())
  adj[x - 1].append(y - 1)
  adj[y - 1].append(x - 1)

queue = deque([0])

while len(queue) > 0:
  cur = queue.popleft()
  for i in adj[cur]:
    if signs[i] == -1:
      queue.append(i)
      signs[i] = cur
      # not_patrolled.remove(i)

if all([sign != -1 for sign in signs[1:]]):
  print("Yes")
  for sign in signs[1:]:
    print(sign + 1)
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, M = map(int, input().split())

adj = [[float("inf") for i in range(N)] for j in range(N)]
signs = [-1 for i in range(N)]
not_patrolled = set(range(1, N))
signs[0] = 1

for _ in range(M):
  x,y = map(int,input().split())
  adj[x - 1][y - 1] = 1
  adj[y - 1][x - 1] = 1

queue = deque([0])

while len(queue) > 0:
  cur = queue.popleft()
  used = set()
  for i in not_patrolled:
    c = adj[cur][i]
    if c == 1:
      queue.append(i)
      signs[i] = cur
      used.add(i)
  hoge = len(not_patrolled)
  not_patrolled = not_patrolled - used
  fuga = len(not_patrolled)
  if hoge == fuga:
    break

if all([sign != -1 for sign in signs]):
  print("Yes")
  for sign in signs[1:]:
    print(sign + 1)
else:
  print("No")

Fixed submission:
from collections import deque
N, M = map(int, input().split())

adj = [[] for i in range(N)]
signs = [-1 for i in range(N)]
# not_patrolled = set(range(1, N))

for _ in range(M):
  x,y = map(int,input().split())
  adj[x - 1].append(y - 1)
  adj[y - 1].append(x - 1)

queue = deque([0])

while len(queue) > 0:
  cur = queue.popleft()
  for i in adj[cur]:
    if signs[i] == -1:
      queue.append(i)
      signs[i] = cur
      # not_patrolled.remove(i)

if all([sign != -1 for sign in signs[1:]]):
  print("Yes")
  for sign in signs[1:]:
    print(sign + 1)
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, M = map(int, input().split())
adj = [[float("inf") for i in range(N)] for j in range(N)]
signs = [-1 for i in range(N)]
non_patrolled = set(range(1, N))
signs[0] = 1

for _ in range(M):
  x,y = map(int,input().split())
  adj[x - 1][y - 1] = 1
  adj[y - 1][x - 1] = 1

queue = deque([0])
dist = 0

while len(queue) > 0:
  cur = queue.popleft()
  used = set()
  for i in non_patrolled:
    c = adj[cur][i]
    if c == 1:
      if signs[i] == -1:
        queue.append(i)
        signs[i] = cur
        used.add(i)
  non_patrolled = non_patrolled - used

if all([sign != -1 for sign in signs]):
  print("Yes")
  for sign in signs[1:]:
    print(sign + 1)
else:
  print("No")

Fixed submission:
from collections import deque
N, M = map(int, input().split())

adj = [[] for i in range(N)]
signs = [-1 for i in range(N)]
# not_patrolled = set(range(1, N))

for _ in range(M):
  x,y = map(int,input().split())
  adj[x - 1].append(y - 1)
  adj[y - 1].append(x - 1)

queue = deque([0])

while len(queue) > 0:
  cur = queue.popleft()
  for i in adj[cur]:
    if signs[i] == -1:
      queue.append(i)
      signs[i] = cur
      # not_patrolled.remove(i)

if all([sign != -1 for sign in signs[1:]]):
  print("Yes")
  for sign in signs[1:]:
    print(sign + 1)
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, M = map(int, input().split())
adj = [[float("inf") for i in range(N)] for j in range(N)]
signs = [-1 for i in range(N)]
signs[0] = 1

for _ in range(M):
  x,y = map(int,input().split())
  adj[x - 1][y - 1] = 1
  adj[y - 1][x - 1] = 1

queue = deque([0])
dist = 0

while len(queue) > 0:
  cur = queue.popleft()
  for i, c in enumerate(adj[cur]):
    if c == 1:
      if signs[i] == -1:
        queue.append(i)
        signs[i] = cur

if all([sign != -1 for sign in signs]):
  print("Yes")
  for sign in signs[1:]:
    print(sign + 1)
else:
  print("No")

Fixed submission:
from collections import deque
N, M = map(int, input().split())

adj = [[] for i in range(N)]
signs = [-1 for i in range(N)]
# not_patrolled = set(range(1, N))

for _ in range(M):
  x,y = map(int,input().split())
  adj[x - 1].append(y - 1)
  adj[y - 1].append(x - 1)

queue = deque([0])

while len(queue) > 0:
  cur = queue.popleft()
  for i in adj[cur]:
    if signs[i] == -1:
      queue.append(i)
      signs[i] = cur
      # not_patrolled.remove(i)

if all([sign != -1 for sign in signs[1:]]):
  print("Yes")
  for sign in signs[1:]:
    print(sign + 1)
else:
  print("No")