N, M = list(map(int, input().split()))

A, B = [], []

graph = [[] for i in range(N+1)]

for i in range(M):

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

    A.append(a)

    B.append(b)

    graph[a].append(b)

    graph[b].append(a)



class Rs():

    def __init__(self):

        self.Rs = []



    def append(self, R):

        self.Rs.append(R)



    def search(self):

        count = 1

        new_nodes, count = self._search(1, count)

        while count < N:

            _new_nodes = set()

            for num in new_nodes:

                _new_node, count = self._search(num, count)

                _new_nodes.update(_new_node)

            new_nodes = _new_nodes



        return [ self.Rs[i].fastest_room for i in range(1,len(self.Rs)) ]



    def _search(self, num, count):

        r = self.Rs[num-1]

        cons = r.connection

        new_nodes = set()

        cons -= r.searched_from



        for con in cons:

            if len(self.Rs[con-1].searched_from) == 0:

                self.Rs[con-1].fastest_room = num

                self.Rs[con-1].searched_from.add(num)

                new_nodes.add(con)

                count += 1

            else:

                continue

        return new_nodes, count



class R():

    def __init__(self, num, connection):

        self.num        = num

        self.connection = connection

        self.searched_from = set([])

        self.fastest_room = None



r = Rs()

for i in range(N):

    r.append(R(i+1, set(graph[i+1])))



l = r.search()

print("Yes")

for room in l:

    print(room)



from collections import deque



N, M = list(map(int, input().split()))

A, B = [], []

graph = [[] for i in range(N+1)]

for i in range(M):

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

    graph[a].append(b)

    graph[b].append(a)



visited = [False for i in range(N+1)]

signs   = [-1 for i in range(N+1)]



D = deque([1])

while D:

    n = D.popleft()

    for node in graph[n]:

        if visited[node] is True:

            continue

        else:

            visited[node] = True

            signs[node] = n

            D.append(node)

print("Yes")

for sign in signs[2:]:

    print(sign)

N, M = list(map(int, input().split()))
A, B = [], []
graph = [[] for i in range(N + 1)]
for i in range(M):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
    graph[a].append(b)
    graph[b].append(a)


class Rs:
    def __init__(self):
        self.Rs = []

    def append(self, R):
        self.Rs.append(R)

    def search(self):
        count = 1
        new_nodes, count = self._search(1, count)
        while count < N:
            _new_nodes = set()
            for num in new_nodes:
                _new_node, count = self._search(num, count)
                _new_nodes.update(_new_node)
            new_nodes = _new_nodes
        return [self.Rs[i].fastest_room for i in range(1, len(self.Rs))]

    def _search(self, num, count):
        r = self.Rs[num - 1]
        cons = r.connection
        new_nodes = set()
        cons -= r.searched_from
        for con in cons:
            if len(self.Rs[con - 1].searched_from) == 0:
                self.Rs[con - 1].fastest_room = num
                self.Rs[con - 1].searched_from.add(num)
                new_nodes.add(con)
                count += 1
            else:
                continue
        return new_nodes, count


class R:
    def __init__(self, num, connection):
        self.num = num
        self.connection = connection
        self.searched_from = set([])
        self.fastest_room = None


r = Rs()
for i in range(N):
    r.append(R(i + 1, set(graph[i + 1])))
l = r.search()
print("Yes")
for room in l:
    print(room)

from collections import deque

N, M = list(map(int, input().split()))
A, B = [], []
graph = [[] for i in range(N + 1)]
for i in range(M):
    a, b = list(map(int, input().split()))
    graph[a].append(b)
    graph[b].append(a)
visited = [False for i in range(N + 1)]
signs = [-1 for i in range(N + 1)]
D = deque([1])
while D:
    n = D.popleft()
    for node in graph[n]:
        if visited[node] is True:
            continue
        else:
            visited[node] = True
            signs[node] = n
            D.append(node)
print("Yes")
for sign in signs[2:]:
    print(sign)

+from collections import deque + -    A.append(a) -    B.append(b) - - -class Rs: -    def __init__(self): -        self.Rs = [] - -    def append(self, R): -        self.Rs.append(R) - -    def search(self): -        count = 1 -        new_nodes, count = self._search(1, count) -        while count < N: -            _new_nodes = set() -            for num in new_nodes: -                _new_node, count = self._search(num, count) -                _new_nodes.update(_new_node) -            new_nodes = _new_nodes -        return [self.Rs[i].fastest_room for i in range(1, len(self.Rs))] - -    def _search(self, num, count): -        r = self.Rs[num - 1] -        cons = r.connection -        new_nodes = set() -        cons -= r.searched_from -        for con in cons: -            if len(self.Rs[con - 1].searched_from) == 0: -                self.Rs[con - 1].fastest_room = num -                self.Rs[con - 1].searched_from.add(num) -                new_nodes.add(con) -                count += 1 -            else: -                continue -        return new_nodes, count - - -class R: -    def __init__(self, num, connection): -        self.num = num -        self.connection = connection -        self.searched_from = set([]) -        self.fastest_room = None - - -r = Rs() -for i in range(N): -    r.append(R(i + 1, set(graph[i + 1]))) -l = r.search() +visited = [False for i in range(N + 1)] +signs = [-1 for i in range(N + 1)] +D = deque([1]) +while D: +    n = D.popleft() +    for node in graph[n]: +        if visited[node] is True: +            continue +        else: +            visited[node] = True +            signs[node] = n +            D.append(node) -for room in l: -    print(room) +for sign in signs[2:]: +    print(sign)