from copy import deepcopy

def main():

    global flags, edges

    n, m = list(map(int, input().split()))



    flags = {e:[n+1, n+1] for e in range(1, n + 1)}

    flags[1][1] = 0

    edges = {e:set() for e in range(1, n + 1)}

    edge_list = []

    for _ in range(m):

        a, b = list(map(int, input().split()))

        edges[a].add(b)

        edges[b].add(a)

        edge_list.append((a, b))



    distance = 1

    node_next = list(edges[1])

    node_next_next = []

    while node_next:

        for next in node_next:

            if flags[next][1] > distance:

                flags[next][1] = distance

                node_next_next += edges[next]

        node_next = deepcopy(node_next_next)

        node_next_next = []

        distance += 1

    for edge in edge_list:

        e1 = edge[0]

        e2 = edge[1]

        if flags[e1][1] == flags[e2][1]:

            pass

        elif flags[e1][1] > flags[e2][1]:

            flags[e1][0] = min(flags[e1][0], e2)

        else:

            flags[e2][0] = min(flags[e2][0], e1)

    result = [flags[f][1] < (n + 1) for f in flags if f > 1]

    if not all(result):

        print('No')

    else:

        print('Yes')

        for i1 in range(2, n + 1):

            print((flags[i1][0]))

            

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.read

readlines = sys.stdin.readlines

from collections import deque

from copy import deepcopy

def main():

    n, m = map(int, input().split())

    edges = {e:[] for e in range(n + 1)}

    for _ in range(m):

        a, b = map(int, input().split())

        edges[a].append(b)

        edges[b].append(a)



    res = [0] * (n + 1)

    dist = 1

    distroom = [n + 1] * (n + 1)

    distroom[1] = 0

    q1 = deque()

    q2 = deque()

    q1.append(1)

    while q1:

        for q1e in q1:

            for adj in edges[q1e]:

                if distroom[adj] > dist:

                    res[adj] = q1e

                    distroom[adj] = dist

                    q2.append(adj)

        dist += 1

        q1 = deepcopy(q2)

        q2 = deque()

    print('Yes')

    print(*res[2:],sep='\n')



if __name__ == '__main__':

    main()

from copy import deepcopy


def main():
    global flags, edges
    n, m = list(map(int, input().split()))
    flags = {e: [n + 1, n + 1] for e in range(1, n + 1)}
    flags[1][1] = 0
    edges = {e: set() for e in range(1, n + 1)}
    edge_list = []
    for _ in range(m):
        a, b = list(map(int, input().split()))
        edges[a].add(b)
        edges[b].add(a)
        edge_list.append((a, b))
    distance = 1
    node_next = list(edges[1])
    node_next_next = []
    while node_next:
        for next in node_next:
            if flags[next][1] > distance:
                flags[next][1] = distance
                node_next_next += edges[next]
        node_next = deepcopy(node_next_next)
        node_next_next = []
        distance += 1
    for edge in edge_list:
        e1 = edge[0]
        e2 = edge[1]
        if flags[e1][1] == flags[e2][1]:
            pass
        elif flags[e1][1] > flags[e2][1]:
            flags[e1][0] = min(flags[e1][0], e2)
        else:
            flags[e2][0] = min(flags[e2][0], e1)
    result = [flags[f][1] < (n + 1) for f in flags if f > 1]
    if not all(result):
        print("No")
    else:
        print("Yes")
        for i1 in range(2, n + 1):
            print((flags[i1][0]))


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
from copy import deepcopy


def main():
    n, m = map(int, input().split())
    edges = {e: [] for e in range(n + 1)}
    for _ in range(m):
        a, b = map(int, input().split())
        edges[a].append(b)
        edges[b].append(a)
    res = [0] * (n + 1)
    dist = 1
    distroom = [n + 1] * (n + 1)
    distroom[1] = 0
    q1 = deque()
    q2 = deque()
    q1.append(1)
    while q1:
        for q1e in q1:
            for adj in edges[q1e]:
                if distroom[adj] > dist:
                    res[adj] = q1e
                    distroom[adj] = dist
                    q2.append(adj)
        dist += 1
        q1 = deepcopy(q2)
        q2 = deque()
    print("Yes")
    print(*res[2:], sep="\n")


if __name__ == "__main__":
    main()

+import sys + +read = sys.stdin.read +readlines = sys.stdin.readlines +from collections import deque -    global flags, edges -    n, m = list(map(int, input().split())) -    flags = {e: [n + 1, n + 1] for e in range(1, n + 1)} -    flags[1][1] = 0 -    edges = {e: set() for e in range(1, n + 1)} -    edge_list = [] +    n, m = map(int, input().split()) +    edges = {e: [] for e in range(n + 1)} -        a, b = list(map(int, input().split())) -        edges[a].add(b) -        edges[b].add(a) -        edge_list.append((a, b)) -    distance = 1 -    node_next = list(edges[1]) -    node_next_next = [] -    while node_next: -        for next in node_next: -            if flags[next][1] > distance: -                flags[next][1] = distance -                node_next_next += edges[next] -        node_next = deepcopy(node_next_next) -        node_next_next = [] -        distance += 1 -    for edge in edge_list: -        e1 = edge[0] -        e2 = edge[1] -        if flags[e1][1] == flags[e2][1]: -            pass -        elif flags[e1][1] > flags[e2][1]: -            flags[e1][0] = min(flags[e1][0], e2) -        else: -            flags[e2][0] = min(flags[e2][0], e1) -    result = [flags[f][1] < (n + 1) for f in flags if f > 1] -    if not all(result): -        print("No") -    else: -        print("Yes") -        for i1 in range(2, n + 1): -            print((flags[i1][0])) +        a, b = map(int, input().split()) +        edges[a].append(b) +        edges[b].append(a) +    res = [0] * (n + 1) +    dist = 1 +    distroom = [n + 1] * (n + 1) +    distroom[1] = 0 +    q1 = deque() +    q2 = deque() +    q1.append(1) +    while q1: +        for q1e in q1: +            for adj in edges[q1e]: +                if distroom[adj] > dist: +                    res[adj] = q1e +                    distroom[adj] = dist +                    q2.append(adj) +        dist += 1 +        q1 = deepcopy(q2) +        q2 = deque() +    print("Yes") +    print(*res[2:], sep="\n")