from collections import deque



N,M,*AB=map(int,open(0).read().split())

to=[[] for _ in range(N)]



for a,b in zip(*[iter(AB)]*2):

  to[a-1].append(b-1)

  to[b-1].append(a-1)

  

q=deque([0])

r=[None]*N



while q:

  x=q.popleft()

  for i in to[x]:

    if r[i] is None:

      q.append(i)

      r[i]=x+1

      

print("Yes",*r[1:],sep="\n")

# D - .. (Double Dots)

from collections import deque





def main():

    N, M, *AB = list(map(int, open(0).read().split()))



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

    for a, b in zip(*[iter(AB)] * 2):

        graph[a].append(b)

        graph[b].append(a)



    # bfs

    queue = deque([1])

    signposts = [0] * (N + 1)

    signposts[1] = 1

    while queue:

        u = queue.popleft()

        for v in graph[u]:

            if not signposts[v]:

                signposts[v] = u

                queue.append(v)



    print("Yes")

    print(("\n".join(map(str, signposts[2:]))))





if __name__ == "__main__":

    main()

from collections import deque

N, M, *AB = map(int, open(0).read().split())
to = [[] for _ in range(N)]
for a, b in zip(*[iter(AB)] * 2):
    to[a - 1].append(b - 1)
    to[b - 1].append(a - 1)
q = deque([0])
r = [None] * N
while q:
    x = q.popleft()
    for i in to[x]:
        if r[i] is None:
            q.append(i)
            r[i] = x + 1
print("Yes", *r[1:], sep="\n")

# D - .. (Double Dots)
from collections import deque


def main():
    N, M, *AB = list(map(int, open(0).read().split()))
    graph = [[] for _ in range(N + 1)]
    for a, b in zip(*[iter(AB)] * 2):
        graph[a].append(b)
        graph[b].append(a)
    # bfs
    queue = deque([1])
    signposts = [0] * (N + 1)
    signposts[1] = 1
    while queue:
        u = queue.popleft()
        for v in graph[u]:
            if not signposts[v]:
                signposts[v] = u
                queue.append(v)
    print("Yes")
    print(("\n".join(map(str, signposts[2:]))))


if __name__ == "__main__":
    main()

+# D - .. (Double Dots) -N, M, *AB = map(int, open(0).read().split()) -to = [[] for _ in range(N)] -for a, b in zip(*[iter(AB)] * 2): -    to[a - 1].append(b - 1) -    to[b - 1].append(a - 1) -q = deque([0]) -r = [None] * N -while q: -    x = q.popleft() -    for i in to[x]: -        if r[i] is None: -            q.append(i) -            r[i] = x + 1 -print("Yes", *r[1:], sep="\n") + +def main(): +    N, M, *AB = list(map(int, open(0).read().split())) +    graph = [[] for _ in range(N + 1)] +    for a, b in zip(*[iter(AB)] * 2): +        graph[a].append(b) +        graph[b].append(a) +    # bfs +    queue = deque([1]) +    signposts = [0] * (N + 1) +    signposts[1] = 1 +    while queue: +        u = queue.popleft() +        for v in graph[u]: +            if not signposts[v]: +                signposts[v] = u +                queue.append(v) +    print("Yes") +    print(("\n".join(map(str, signposts[2:])))) + + +if __name__ == "__main__": +    main()