Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra_back(s,t,n,w,cost):
    #sからtへの最短経路の経路復元
    prev = [s] * n #最短経路の直前の頂点
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
        
        for i in range(n):
            if d[i] > d[v] + cost[v][i]: 
                d[i] = d[v] + cost[v][i]
                prev[i] = v
        
    path = [t]
    while prev[t] != s:
        path.append(prev[t])
        prev[t] = prev[prev[t]]
    path.append(s)
    path = path[::-1]
    return path

################################
n,w = map(int,input().split()) #n:頂点数　w:辺の数

cost = [[float("inf") for i in range(n)] for i in range(n)] 
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(w):
    x,y = map(int,input().split())
    x-=1
    y-=1
    cost[x][y] = 1
    cost[y][x] = 1
sp = [0 for _ in range(n-1)]

for i in range(1,n):
    sp[i-1] = dijkstra_back(0,i,n,w,cost)

sp.sort()
#print(*sp)
sg = [-1 for _ in range(n)]
for l in sp:
    for j in range(len(l)):
        x = l[j]
        if j != 0:
            #print(l,x)
            if sg[x] == -1:
                sg[x] = l[j-1]
            elif sg[x] !=  l[j-1]:
                print('No')
                exit()

print('Yes')
for i in range(1,n):
    print(sg[i]+1)



Fixed submission:
from collections import deque



n,m = map(int,input().split())
ab = [[] for _ in range(m)]
kr = [[] for _ in range(n)]
dist = [-1 for _ in range(n)]
dist[0] = 0
ans = [-1 for _ in range(n)]
qn = deque([1])
for i in range(m):
    a,b = map(int,input().split())
    a,b = min(a,b),max(a,b)
    ab[i] = [a,b]
    kr[a-1].append(b)
    kr[b-1].append(a)

dis = 1
while len(qn) > 0:
    v = qn.popleft()
    d = dist[v-1]
    for w in kr[v-1]:
        if dist[w-1] > -1:
            continue
        dist[w-1] = d + 1
        qn.append(w)
        ans[w-1] = v


#print(dist)

#ab.sort()
#print(ab)
#print(kr)

print('Yes')
for i in range(1,n):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra_back(s,t,n,w,cost):
    #sからtへの最短経路の経路復元
    prev = [s] * n #最短経路の直前の頂点
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
        
        for i in range(n):
            if d[i] > d[v] + cost[v][i]: 
                d[i] = d[v] + cost[v][i]
                prev[i] = v
        
    path = [t]
    while prev[t] != s:
        path.append(prev[t])
        prev[t] = prev[prev[t]]
    path.append(s)
    path = path[::-1]
    return path

################################
n,w = map(int,input().split()) #n:頂点数　w:辺の数

cost = [[float("inf") for i in range(n)] for i in range(n)] 
#cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(w):
    x,y = map(int,input().split())
    x-=1
    y-=1
    cost[x][y] = 1
    cost[y][x] = 1
sp = [0 for _ in range(n-1)]

for i in range(1,n):
    sp[i-1] = dijkstra_back(0,i,n,w,cost)

sp.sort()
#print(*sp)
sg = [-1 for _ in range(n)]
for l in sp:
    for j in range(len(l)):
        x = l[j]
        if j != 0:
            #print(l,x)
            if sg[x] == -1:
                sg[x] = l[j-1]
            elif sg[x] !=  l[j-1]:
                print('No')
                exit()

print('Yes')
for i in range(1,n):
    print(sg[i]+1)



Fixed submission:
from collections import deque



n,m = map(int,input().split())
ab = [[] for _ in range(m)]
kr = [[] for _ in range(n)]
dist = [-1 for _ in range(n)]
dist[0] = 0
ans = [-1 for _ in range(n)]
qn = deque([1])
for i in range(m):
    a,b = map(int,input().split())
    a,b = min(a,b),max(a,b)
    ab[i] = [a,b]
    kr[a-1].append(b)
    kr[b-1].append(a)

dis = 1
while len(qn) > 0:
    v = qn.popleft()
    d = dist[v-1]
    for w in kr[v-1]:
        if dist[w-1] > -1:
            continue
        dist[w-1] = d + 1
        qn.append(w)
        ans[w-1] = v


#print(dist)

#ab.sort()
#print(ab)
#print(kr)

print('Yes')
for i in range(1,n):
    print(ans[i])