There is a cave.  The cave has N rooms and M passages. The rooms are numbered 1 to N, and the passages are numbered 1 to M. Passage i connects Room A_i and Room B_i bidirectionally. One can travel between any two rooms by traversing passages. Room 1 is a special room with an entrance from the outside.  It is dark in the cave, so we have decided to place a signpost in each room except Room 1. The signpost in each room will point to one of the rooms directly connected to that room with a passage.  Since it is dangerous in the cave, our objective is to satisfy the condition below for each room except Room 1.    * If you start in that room and repeatedly move to the room indicated by the signpost in the room you are in, you will reach Room 1 after traversing the minimum number of passages possible.  Determine whether there is a way to place signposts satisfying our objective, and print one such way if it exists.
n, m = map(int, input().split())

list_a = []
list_b = []

for i in range(m):
    a, b = map(int, input().split())
    list_a.append(a)
    list_b.append(b)

room_signpost = [0] * n


def recursive(a_list, b_list, rooms):
    next_rooms = []
    for room in rooms:

        roomindexes_a = [idx for idx, val in enumerate(a_list) if val == room]
        roomindexes_b = [idx for idx, val in enumerate(b_list) if val == room]

        for i in roomindexes_a:
            next_rooms.append(b_list[i])
            if room_signpost[b_list[i] - 1] == 0:
                room_signpost[b_list[i] - 1] = room
            else:
                pass
        for i in roomindexes_b:
            next_rooms.append(a_list[i])
            if room_signpost[a_list[i] - 1] == 0:
                room_signpost[a_list[i] - 1] = room
            else:
                pass

        del_index = sorted(roomindexes_a + roomindexes_b, reverse=True)

        for idx in del_index:
            del a_list[idx]
            del b_list[idx]

        print(a_list)
        print(b_list)
        print(next_rooms)

    if not next_rooms:
        return
    else:
        recursive(a_list, b_list, next_rooms)

recursive(list_a, list_b, [1])

room_signpost[0] = "Yes"
for row in room_signpost:
    print(row)
import queue
N, M = map(int, input().split())
adj = [[]for i in range(N+1)]
parent = [-1] * (N+1)  
for m in range(M):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
q = queue.Queue()  
q.put((1, 0))  
while(not q.empty()):
    x, p = q.get()
    if parent[x] != -1:  
        continue
    parent[x] = p
    for next in adj[x]:
        if parent[next] == -1:  
            q.put((next, x))  
print('Yes')  
for p in parent[2:]:  
    print(p)
