Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

edges = [ [] for _ in range(n) ]

for _ in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

INF = 10 ** 6

def dijkstra_travel(edges):
    dists = [ INF  for _ in range(n) ]
    paths = [ None for _ in range(n) ]

    dists[0] = 0
    paths[0] = 0

    def travel_adjacent(n):
        adjacent_nodes = list(
            map(
                lambda node: (node, paths[node]),
                edges[n],
            )
        )

        next_travel = []

        for node, path in adjacent_nodes:
            if path is None or dists[node] > dists[n] + 1:
                dists[node] = dists[n] + 1
                paths[node] = n
                next_travel.append(node)

        for x in next_travel:
            travel_adjacent(x)

    travel_adjacent(0)

    return paths[1:]

result = dijkstra_travel(edges)

if all(map(lambda x: x is not None, result)):
    print('Yes')

    for x in result:
        print(x + 1)

else:
    print('No')

Fixed submission:
n, m = map(int, input().split())

edges = [ [] for _ in range(n) ]

for _ in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

INF = 10 ** 6

def dijkstra_travel(edges):
    dists = [ INF  for _ in range(n) ]
    paths = [ None for _ in range(n) ]

    dists[0] = 0
    paths[0] = 0

    next_travel = [ 0 ]

    def travel_adjacent():
        n = next_travel.pop(0)

        adjacent_nodes = list(
            map(
                lambda node: (node, paths[node]),
                edges[n],
            )
        )

        for node, path in adjacent_nodes:
            if path is None or dists[node] > dists[n] + 1:
                dists[node] = dists[n] + 1
                paths[node] = n
                next_travel.append(node)


    while len(next_travel) > 0:
        travel_adjacent()

    return paths[1:]

result = dijkstra_travel(edges)

if all(map(lambda x: x is not None, result)):
    print('Yes')

    for x in result:
        print(x + 1)

else:
    print('No')

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

edges = [ [] for _ in range(n) ]

for _ in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

INF = 10 ** 10

def dijkstra_travel(edges):
    paths = [ None for _ in range(n) ]
    paths[0] = 0

    def travel_adjacent(n):
        adjacent_nodes = list(
            map(
                lambda x: paths[x],
                edges[n],
            )
        )

        next_travel = []

        for i, node in enumerate(adjacent_nodes):
            if node is None:
                paths[edges[n][i]] = n
                next_travel.append(edges[n][i])

        for x in next_travel:
            travel_adjacent(x)

    travel_adjacent(0)

    return paths[1:]

result = dijkstra_travel(edges)

if all(map(lambda x: x is not None, result)):
    print('Yes')

    for x in result:
        print(x + 1)

else:
    print('No')

Fixed submission:
n, m = map(int, input().split())

edges = [ [] for _ in range(n) ]

for _ in range(m):
    a, b = map(int, input().split())
    edges[a - 1].append(b - 1)
    edges[b - 1].append(a - 1)

INF = 10 ** 6

def dijkstra_travel(edges):
    dists = [ INF  for _ in range(n) ]
    paths = [ None for _ in range(n) ]

    dists[0] = 0
    paths[0] = 0

    next_travel = [ 0 ]

    def travel_adjacent():
        n = next_travel.pop(0)

        adjacent_nodes = list(
            map(
                lambda node: (node, paths[node]),
                edges[n],
            )
        )

        for node, path in adjacent_nodes:
            if path is None or dists[node] > dists[n] + 1:
                dists[node] = dists[n] + 1
                paths[node] = n
                next_travel.append(node)


    while len(next_travel) > 0:
        travel_adjacent()

    return paths[1:]

result = dijkstra_travel(edges)

if all(map(lambda x: x is not None, result)):
    print('Yes')

    for x in result:
        print(x + 1)

else:
    print('No')