Problem:
There is a cave.  The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.  It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.  Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.    * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.  Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.

Incorrect submission (verdict: Wrong Answer):

import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
import copy as cp
import sys
def sinput(): return sys.stdin.readline()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(): return list(imap())
def farr(): return list(fmap())
def sarr(): return sinput().split()
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf


n,m = imap()
ab = np.array([iarr()+[1] for i in range(m)])
a,b,c = ab.T[0]-1, ab.T[1]-1, ab.T[2]

adja = [[] for i in range(n)]
for i in range(m):
    aa,bb = a[i],b[i]
    adja[aa].append(bb)
    adja[bb].append(aa)
    
graph = sps.csr_matrix((c,(a,b)), (n,n)) 
dk = sps.csgraph.dijkstra(graph,directed=0,indices=0).astype(int)

for i in range(1,n):
    option = adja[i]
    min = np.inf
    ans = -1
    for num in option:
        if dk[num] < min: ans = num; min = dk[num]
    print(ans+1)
        


Fixed, accepted submission:
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
def adj(n): return [[] for _ in range(n)]

n,m = imap()
ab = np.array([iarr() for i in range(m)])
g = adj(n+1)
for i in range(m):
    aa,bb = ab[i][0],ab[i][1]
    g[aa].append(bb)
    g[bb].append(aa)

dep = iarr(n+1)
dep[1] = 1
q = col.deque([1])
route = iarr(n+1)
while q:
    now = q.popleft()
    for next in g[now]:
        if dep[next]: continue
        else:
            q.append(next)
            dep[next] = dep[now]+1
            route[next] = now

print("Yes")
for ans in route[2:]: print(ans)