Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
b=[]
C=[1]
D=[1]
s=[0 for i in range(n)]
s[0] = "Yes"
 
for i in range(m):
  c,d=map(int,input().split())
  a.append(c)
  b.append(d)
 
def Next(be):
  A=[a[i] for i in range(len(a)) if a[i] == be or b[i] == be]
  B=[b[i] for i in range(len(b)) if b[i] == be or a[i] == be]
  A=[i for i in A if i != be]
  B=[i for i in B if i != be]
  A.extend(B)
  for i in A:
    if s[i-1] == 0:
      s[i-1] = be
  return A
 
while True:
  if s.count(0)==0:
    break
  for i in C:
    D=Next(i)
    C = D
for i in s:
  print(i)

Fixed submission:
from collections import deque

N, M=map(int,input().split())
a=[]
b=[]
for i in range(M):
  A,B=map(int,input().split())
  a.append(A)
  b.append(B)

graph = [[] for _ in range(N + 1)]
for i in range(M):
  graph[a[i]].append(b[i])
  graph[b[i]].append(a[i])

    # bfs
queue = deque([1])
signposts = [0] * (N + 1)
signposts[1] = 1
while queue:#キューが空になるまで
  u = queue.popleft()
  for v in graph[u]:
    if not signposts[v]:
      signposts[v] = u
      queue.append(v)
 
if all(signposts[2:]):
  print("Yes")
  print("\n".join(map(str, signposts[2:])))
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
b=[]
C=[]
s=[0 for i in range(n)]
s[0] = "Yes"
 
for i in range(m):
  c,d=map(int,input().split())
  a.append(c)
  b.append(d)
 
def Next(be):
  C.clear()
  for j in be:
    for i in range(len(a)):
      if a[i] == j:
        if s[b[i]-1]==0 and 0 == be.count(b[i]):
          C.append(b[i])
          s[b[i]-1]=j
        continue

      if b[i] == j: 
        if s[a[i]-1]==0 and 0 == be.count(a[i]):
          C.append(a[i])
          s[a[i]-1]=j
        continue
    Dele(j)
  return C

def Dele(be):
  for j in range(a.count(be)):
    a.remove(be)
  for j in range(b.count(be)):
    b.remove(be)

co=[1]
while True:
  if s.count(0) == 0:
    break
  co = Next(list(co))
 
for i in s:
  print(i)

Fixed submission:
from collections import deque

N, M=map(int,input().split())
a=[]
b=[]
for i in range(M):
  A,B=map(int,input().split())
  a.append(A)
  b.append(B)

graph = [[] for _ in range(N + 1)]
for i in range(M):
  graph[a[i]].append(b[i])
  graph[b[i]].append(a[i])

    # bfs
queue = deque([1])
signposts = [0] * (N + 1)
signposts[1] = 1
while queue:#キューが空になるまで
  u = queue.popleft()
  for v in graph[u]:
    if not signposts[v]:
      signposts[v] = u
      queue.append(v)
 
if all(signposts[2:]):
  print("Yes")
  print("\n".join(map(str, signposts[2:])))
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
b=[]
C=[]
s=[0 for i in range(n)]
s[0] = "Yes"
 
for i in range(m):
  c,d=map(int,input().split())
  a.append(c)
  b.append(d)
 
def Next(be):
  C.clear()
  for j in be:
    for i in range(len(a)):
      if a[i] == j:
        if s[b[i]-1]==0 and 0 == be.count(b[i]):
          C.append(b[i])
          s[b[i]-1]=j
        continue

      if b[i] == j: 
        if s[a[i]-1]==0 and 0 == be.count(a[i]):
          C.append(a[i])
          s[a[i]-1]=j
        continue
    Dele(j)
  return C

def Dele(be):
  for j in range(a.count(be)):
    a.remove(be)
  for j in range(b.count(be)):
    b.remove(be)

co=[1]
for i in range(5):
  if s.count(0) == 0:
    break
  co = Next(list(co))
 
for i in s:
  print(i)

Fixed submission:
from collections import deque

N, M=map(int,input().split())
a=[]
b=[]
for i in range(M):
  A,B=map(int,input().split())
  a.append(A)
  b.append(B)

graph = [[] for _ in range(N + 1)]
for i in range(M):
  graph[a[i]].append(b[i])
  graph[b[i]].append(a[i])

    # bfs
queue = deque([1])
signposts = [0] * (N + 1)
signposts[1] = 1
while queue:#キューが空になるまで
  u = queue.popleft()
  for v in graph[u]:
    if not signposts[v]:
      signposts[v] = u
      queue.append(v)
 
if all(signposts[2:]):
  print("Yes")
  print("\n".join(map(str, signposts[2:])))
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
b=[]
C=[]
s=[0 for i in range(n)]
s[0] = "Yes"
 
for i in range(m):
  c,d=map(int,input().split())
  a.append(c)
  b.append(d)
 
def Next(be):
  C.clear()
  for j in be:
    for i in range(len(a)):
      if a[i] == j:
        
        if s[b[i]-1]==0 and 0 == be.count(b[i]):
          C.append(b[i])
          s[b[i]-1]=j
        continue
      if b[i] == j:
        
        if s[a[i]-1]==0 and 0 == be.count(a[i]):
          C.append(a[i])
          s[a[i]-1]=j
        continue
  return C
co=[1]
for i in range(m):
  if s.count(0) == 0:
    break
  co = Next(list(co))
 
for i in s:
  print(i)

Fixed submission:
from collections import deque

N, M=map(int,input().split())
a=[]
b=[]
for i in range(M):
  A,B=map(int,input().split())
  a.append(A)
  b.append(B)

graph = [[] for _ in range(N + 1)]
for i in range(M):
  graph[a[i]].append(b[i])
  graph[b[i]].append(a[i])

    # bfs
queue = deque([1])
signposts = [0] * (N + 1)
signposts[1] = 1
while queue:#キューが空になるまで
  u = queue.popleft()
  for v in graph[u]:
    if not signposts[v]:
      signposts[v] = u
      queue.append(v)
 
if all(signposts[2:]):
  print("Yes")
  print("\n".join(map(str, signposts[2:])))
else:
  print("No")

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
a=[]
b=[]
C=[]
s=[0 for i in range(n)]
s[0] = "Yes"
 
for i in range(m):
  c,d=map(int,input().split())
  a.append(c)
  b.append(d)
 
def Next(be):
  C.clear()
  for j in be:
    for i in range(len(a)):
      if a[i] == j:
        
        if s[b[i]-1]==0 and 0 == be.count(b[i]):
          C.append(b[i])
          s[b[i]-1]=j
        continue
      if b[i] == j:
        
        if s[a[i]-1]==0 and 0 == be.count(a[i]):
          C.append(a[i])
          s[a[i]-1]=j
        continue
  return C
co=[1]
while True:
  if s.count(0) == 0:
    break
  co = Next(list(co))
 
for i in s:
  print(i)

Fixed submission:
from collections import deque

N, M=map(int,input().split())
a=[]
b=[]
for i in range(M):
  A,B=map(int,input().split())
  a.append(A)
  b.append(B)

graph = [[] for _ in range(N + 1)]
for i in range(M):
  graph[a[i]].append(b[i])
  graph[b[i]].append(a[i])

    # bfs
queue = deque([1])
signposts = [0] * (N + 1)
signposts[1] = 1
while queue:#キューが空になるまで
  u = queue.popleft()
  for v in graph[u]:
    if not signposts[v]:
      signposts[v] = u
      queue.append(v)
 
if all(signposts[2:]):
  print("Yes")
  print("\n".join(map(str, signposts[2:])))
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
a=[]
b=[]
C=[]
s=[0 for i in range(n)]
s[0] = "Yes"

for i in range(m):
  a,b=map(int,input().split())

def Next(be):
  C.clear()
  for j in be:
    for i in range(len(a)):
      if len(a) <= i:
        break
      if a[i] == j:
        
        if s[b[i]-1]==0 and 0 == be.count(b[i]):
          C.append(b[i])
          s[b[i]-1]=j
        continue
      if b[i] == j:
        
        if s[a[i]-1]==0 and 0 == be.count(a[i]):
          C.append(a[i])
          s[a[i]-1]=j
        continue
  return C
co=[1]

while True:
  if s.count(0) == 0:
    break
  co = Next(list(co))

for i in s:
  print(i)

Fixed submission:
from collections import deque

N, M=map(int,input().split())
a=[]
b=[]
for i in range(M):
  A,B=map(int,input().split())
  a.append(A)
  b.append(B)

graph = [[] for _ in range(N + 1)]
for i in range(M):
  graph[a[i]].append(b[i])
  graph[b[i]].append(a[i])

    # bfs
queue = deque([1])
signposts = [0] * (N + 1)
signposts[1] = 1
while queue:#キューが空になるまで
  u = queue.popleft()
  for v in graph[u]:
    if not signposts[v]:
      signposts[v] = u
      queue.append(v)
 
if all(signposts[2:]):
  print("Yes")
  print("\n".join(map(str, signposts[2:])))
else:
  print("No")