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

def dijkstra(start,node,edge):
    d = [2*10**5] * node
    m = [0]*node
    d[start] = 0
    q = [0]
    heapify(q)
    
    while(len(q) != 0):
      i = heappop(q)
      di = d[i]
      for j in edge[i]:
        if(d[j] > di+1):
          d[j] = di + 1
          heappush(q, j)
          m[j] = i+1
    return m

def main():
    N,M = map(int, input().split())
    
    E = [[] for _ in [0]*N]
    for i in range(M):
      a,b = (int(x) for x in input().split())
      E[a-1].append(b-1)
      E[b-1].append(a-1)

    m = dijkstra(0, N, E)
    print("Yes")
    print("\n".join(map(str, m[1:])))

if __name__ == '__main__':
    main()


Fixed submission:
from heapq import heapify, heappop, heappush

def dijkstra(start,node,edge):
    d = [2*10**5] * node
    m = [0]*node
    d[start] = 0
    q = [(0,0)]
    heapify(q)
    
    while(len(q) != 0):
      ci, i = heappop(q)
      di = d[i]
      for j in edge[i]:
        if(d[j] > di+1):
          d[j] = di + 1
          heappush(q, (di+1,j))
          m[j] = i+1
    return m

def main():
    N,M = map(int, input().split())
    
    E = [[] for _ in [0]*N]
    for i in range(M):
      a,b = (int(x) for x in input().split())
      E[a-1].append(b-1)
      E[b-1].append(a-1)

    m = dijkstra(0, N, E)
    print("Yes")
    print("\n".join(map(str, m[1:])))

if __name__ == '__main__':
    main()

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

def dijkstra(start,node,edge):
    d = [2*10**5] * node
    m = [0]*node
    d[start] = 0
    q = [0]
    heapify(q)
    
    while(len(q) != 0):
      i = heappop(q)
      for j in edge[i]:
        if(d[j] > d[i]+1):
          d[j] = d[i] + 1
          heappush(q, j)
          m[j] = i+1
    return m

def main():
    N,M = map(int, input().split())
    
    E = [[] for _ in [0]*N]
    for i in range(M):
      a,b = (int(x) for x in input().split())
      E[a-1].append(b-1)
      E[b-1].append(a-1)

    m = dijkstra(0, N, E)
    print("Yes")
    # for i in range(1,N):
    #   print(m[i]+1)
    print("\n".join(map(str, m[1:])))

if __name__ == '__main__':
    main()


Fixed submission:
from heapq import heapify, heappop, heappush

def dijkstra(start,node,edge):
    d = [2*10**5] * node
    m = [0]*node
    d[start] = 0
    q = [(0,0)]
    heapify(q)
    
    while(len(q) != 0):
      ci, i = heappop(q)
      di = d[i]
      for j in edge[i]:
        if(d[j] > di+1):
          d[j] = di + 1
          heappush(q, (di+1,j))
          m[j] = i+1
    return m

def main():
    N,M = map(int, input().split())
    
    E = [[] for _ in [0]*N]
    for i in range(M):
      a,b = (int(x) for x in input().split())
      E[a-1].append(b-1)
      E[b-1].append(a-1)

    m = dijkstra(0, N, E)
    print("Yes")
    print("\n".join(map(str, m[1:])))

if __name__ == '__main__':
    main()

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

def dijkstra(start,node,edge):
    d = [2*10**5] * node
    m = [0]*node
    d[start] = 0
    q = [0]
    heapify(q)
    
    while(len(q) != 0):
      i = heappop(q)
      for j in edge[i]:
        if(d[j] > d[i] + 1):
          d[j] = d[i] + 1
          heappush(q, j)
          m[j] = i
    return d, m

def main():
    N,M = map(int, input().split())
    
    E = [[] for _ in [0]*N]
    
    for i in range(M):
      a,b = (int(x) for x in input().split())
      E[a-1].append(b-1)
      E[b-1].append(a-1)

    d, m = dijkstra(0, N, E)
    # print(d, m)
    print("Yes")
    for i in range(1,N):
      print(m[i]+1)

if __name__ == '__main__':
    main()


Fixed submission:
from heapq import heapify, heappop, heappush

def dijkstra(start,node,edge):
    d = [2*10**5] * node
    m = [0]*node
    d[start] = 0
    q = [(0,0)]
    heapify(q)
    
    while(len(q) != 0):
      ci, i = heappop(q)
      di = d[i]
      for j in edge[i]:
        if(d[j] > di+1):
          d[j] = di + 1
          heappush(q, (di+1,j))
          m[j] = i+1
    return m

def main():
    N,M = map(int, input().split())
    
    E = [[] for _ in [0]*N]
    for i in range(M):
      a,b = (int(x) for x in input().split())
      E[a-1].append(b-1)
      E[b-1].append(a-1)

    m = dijkstra(0, N, E)
    print("Yes")
    print("\n".join(map(str, m[1:])))

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

# class Node:
#     def __init__(self, n, N):
#         self.id = n
#         self.edges = []
#         self.dist = 2*10**5
#         self.nroom = -1

#     def set_edge(self, e):
#         self.edges.append(e)    
    
#     def set_dist(self, e, i):
#         if e < self.dist:
#             self.dist = e
#             self.nroom = i


from heapq import *

def dijkstra(start,node,edge):
    d = [float("inf")] * node
    m = [0]*node
    d[start] = 0
    #スタートをキューに入れる
    q = [0]
    heapify(q)
    
    while(len(q) != 0):
      i = heappop(q)
    #   print(i)  
      for j in edge[i]:
        if(d[j] > d[i] + 1):
          d[j] = d[i] + 1
          heappush(q, j)
          m[j] = i
    return d, m

def main():
    N,M = map(int, input().split())
    
    E = [[] for _ in [0]*N]
    
    for i in range(M):
      a,b = (int(x) for x in input().split())
      E[a-1].append(b-1)
      E[b-1].append(a-1)

    d, m = dijkstra(0, N, E)
    # print(d, m)
    print("Yes")
    for i in range(1,N):
      print(m[i]+1)

if __name__ == '__main__':
    main()


Fixed submission:
from heapq import heapify, heappop, heappush

def dijkstra(start,node,edge):
    d = [2*10**5] * node
    m = [0]*node
    d[start] = 0
    q = [(0,0)]
    heapify(q)
    
    while(len(q) != 0):
      ci, i = heappop(q)
      di = d[i]
      for j in edge[i]:
        if(d[j] > di+1):
          d[j] = di + 1
          heappush(q, (di+1,j))
          m[j] = i+1
    return m

def main():
    N,M = map(int, input().split())
    
    E = [[] for _ in [0]*N]
    for i in range(M):
      a,b = (int(x) for x in input().split())
      E[a-1].append(b-1)
      E[b-1].append(a-1)

    m = dijkstra(0, N, E)
    print("Yes")
    print("\n".join(map(str, m[1:])))

if __name__ == '__main__':
    main()