Buggy python submission (verdict: Time Limit Exceeded):
# from collections import defaultdict
import numpy as np
from scipy.sparse.csgraph import shortest_path

def get_path(start, goal, pred):
    return get_path_row(start, goal, pred[start])

def get_path_row(start, goal, pred_row):
    path = []
    i = goal
    while i != start and i >= 0:
        path.append(i)
        i = pred_row[i]
    if i < 0:
        return []
    path.append(i)
    return path[::-1]

n, m = map(int, input().split())
a, b = [], []
for _ in range(m):
    ai, bi =  map(int, input().split())
    a.append(ai)
    b.append(bi)

graph = [[0 for _ in range(n)] for _ in range(n)]
for ai, bi in zip(a, b):
    graph[ai - 1][bi - 1], graph[bi - 1][ai - 1] = 1, 1
graph = np.array(graph)
signs = [set() for _ in range(n)]
# print(graph)
shortest, pathes = shortest_path(graph, return_predecessors=True)
# print(shortest)
# print(pathes)
for i in range(1, n):
    path = get_path(i, 0, pathes)
    # print(i, path)
    # print(get_path(i, 0, pathes)[1:-1])
    for j in range(len(path) - 1):
        # print(f'{path[j + 1]} is signed at {path[j]}')
        signs[path[j]].add(path[j + 1])
# print(signs)

is_ok = True
for sign in signs:
    if len(sign) > 1:
        is_ok = False
        break

if is_ok:
    print('Yes')
    for sign in signs[1:]:
        print(sign.pop() + 1)
else:
    print('No')

Fixed submission:
from collections import deque
import sys


def I(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))


INF = float('inf')


class Graph:
    def __init__(self, n, is_directed=False):
        self.graph = [[] for _ in range(n)]
        self.is_directed = is_directed

    def add_edge(self, u, v):
        """頂点uから頂点vに辺を作る
        無向グラフの場合、uからvの方向の辺のみを記録する
        """
        self.graph[u].append(v)
        if not self.is_directed:
            self.graph[v].append(u)

    def bfs(self, start):
        """幅優先探索を行い始点から各頂点までの距離の配列を返す
        """
        distances = [INF] * len(self.graph)
        queue = deque([start])
        distances[start] = 0
        ans = [0] * len(self.graph)

        while queue:
            now = queue.popleft()
            for to in self.graph[now]:
                if distances[to] != INF:
                    continue
                queue.append(to)
                ans[to] = now
                distances[to] = distances[now] + 1
        return distances, ans

    def dfs(self, start):
        """幅優先探索を行い始点から各頂点までの距離の配列を返す
        """
        distances = [INF] * len(self.graph)
        queue = deque([start])
        distances[start] = 0
        ans = [0] * len(self.graph)

        while queue:
            now = queue.pop()
            for to in self.graph[now]:
                if distances[to] != INF:
                    continue
                queue.append(to)
                # 前の頂点からこの頂点に対する道標を建てる
                ans[to] = now
                distances[to] = distances[now] + 1
        return distances, ans


def main():
    n, m = LI()
    g = Graph(n)
    for _ in range(m):
        a, b = LI()
        a, b = a - 1, b - 1
        g.add_edge(a, b)

    bfs_res, ans = g.bfs(0)
    for d in bfs_res:
        if d == INF:
            print('No')
            return

    print('Yes')
    print(*map(lambda x: x + 1, ans[1:]), sep='\n')


if __name__ == '__main__':
    main()