Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[0] * (n+1) for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a][b] = 1
    ggg[b][a] = 1
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in range(1, n+1):
      if ggg[a][b] and not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()


Fixed submission:
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[] for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a].append(b)
    ggg[b].append(a)
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in ggg[a]:
      if not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[0] * (n+1) for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a][b] = 1
    ggg[b][a] = 1
    
  qq = deque()
  qq.append((1, 1))
  
  while qq:
    a, f = qq.popleft()
    for b in range(1, n+1):
      if ggg[a][b] and not ff[b]:
        ff[b] = a
        qq.append((b, a))
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()


Fixed submission:
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[] for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a].append(b)
    ggg[b].append(a)
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in ggg[a]:
      if not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[0] * (n+1) for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a][b] = 1
    ggg[b][a] = 1
    
  qq = deque()
  qq.append((1, 1))
  
  while qq:
    a, f = qq.popleft()
    if ff[a]:
      continue
    ff[a] = f
    for b in range(1, n+1):
      if ggg[a][b] and not ff[b]:
        qq.append((b, a))
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()


Fixed submission:
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[] for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a].append(b)
    ggg[b].append(a)
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in ggg[a]:
      if not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[0] * (n+1) for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a][b] = 1
    ggg[b][a] = 1
    
  qq = deque()
  qq.append((1, 1))
  
  while qq:
    a, f = qq.popleft()
    if ff[a]:
      continue
    ff[a] = f
    for b in range(1, n+1):
      if ggg[a][b]:
        qq.append((b, a))
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)
 
  
  
  
if __name__ == '__main__':
  main()


Fixed submission:
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[] for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a].append(b)
    ggg[b].append(a)
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in ggg[a]:
      if not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

INT_MAX = 10 ** 9


def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  g = [[0] * (n+1) for i in range(n+1)]
  gp = [INT_MAX] * (n+1)
  gf = [0] * (n+1)
  
  for a, b in ab:
    g[a][b] = 1
    g[b][a] = 1
  
  h = [(0, 1, 1)]
  
  while h:
    if all(0 < i < INT_MAX for i in gf[2:]):
      break
    p, b, a = heappop(h)
    if p < gp[b]:
      gp[b] = p
      gf[b] = a
    else:
      continue
    for x in range(1, n+1):
      if g[b][x]:
        heappush(h, (p + 1, x, b))
  
  r = gf[2:]
  s = 'Yes' if all(0 < i < INT_MAX for i in r) else 'No'
  print(s)
  if s == 'Yes':
    for i in r:
      print(i)
  
  
  
if __name__ == '__main__':
  main()


Fixed submission:
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[] for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a].append(b)
    ggg[b].append(a)
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in ggg[a]:
      if not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

INT_MAX = 10 ** 9


def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  g = [[0] * (n+1) for i in range(n+1)]
  gp = [INT_MAX] * (n+1)
  gf = [0] * (n+1)
  
  for a, b in ab:
    g[a][b] = 1
    g[b][a] = 1
  
  h = [(0, 1, 1)]
  
  while h:
    p, a, b = heappop(h)
    if p < gp[a]:
      gp[a] = p
      gf[a] = b
    else:
      continue
    for z in range(1, n+1):
      if g[a][z]:
        heappush(h, (p + g[a][b], z, a))
  
  r = gf[2:]
  s = 'Yes' if all(0 < i < INT_MAX for i in r) else 'No'
  print(s)
  if s == 'Yes':
    for i in r:
      print(i)
  
  
  
if __name__ == '__main__':
  main()


Fixed submission:
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[] for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a].append(b)
    ggg[b].append(a)
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in ggg[a]:
      if not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop

INT_MAX = 10 ** 9


def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  g = [[0] * (n+1) for i in range(n+1)]
  gp = [INT_MAX] * (n+1)
  gf = [0] * (n+1)
  
  for a, b in ab:
    g[a][b] = 1
    g[b][a] = 1
  
  h = [(1, 1, 0)]
  
  while h:
    a, b, p = heappop(h)
    if p < gp[a]:
      gp[a] = p
      gf[a] = b
    else:
      continue
    for z in range(1, n+1):
      if g[a][z]:
        heappush(h, (z, a, p + g[a][b]))
  
  r = gf[2:]
  s = 'Yes' if all(0 < i < INT_MAX for i in r) else 'No'
  print(s)
  if s == 'Yes':
    for i in r:
      print(i)
  
  
  
if __name__ == '__main__':
  main()


Fixed submission:
from collections import deque

def main():
  n, m = map(int, input().split())
  ab = (map(int, input().split()) for i in range(m))
  
  ggg = [[] for i in range(n+1)]
  ff = [0] * (n+1)
  
  for a, b in ab:
    ggg[a].append(b)
    ggg[b].append(a)
    
  qq = deque()
  qq.append(1)
  ff[1] = 1
  
  while qq:
    a = qq.popleft()
    for b in ggg[a]:
      if not ff[b]:
        ff[b] = a
        qq.append(b)
  
  rr = ff[2:]
  y = all(rr)
  
  print('Yes' if y else 'No')
  if y:
    for r in rr:
      print(r)

if __name__ == '__main__':
  main()