import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



from collections import deque 

def main():

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

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

    for _ in range(M):

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

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

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



    dq = deque()

    dq.append(0)

    done = [0 for _ in range(N)]

    done[0] = 1

    ans = [0 for _ in range(N)]

    while len(dq) > 0:

        v = dq.popleft()

        for nx in to[v]:

            if done[nx]:

                continue

            ans[nx] = v

            done[nx] = 1

            dq.append(nx) 

    print('Yes')

    for i in ans[1:]:

        print((i+1))

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



from collections import deque 

def main():

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

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

    for _ in range(m):

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

        a-=1

        b-=1

        to[a].append(b)

        to[b].append(a)



    dq = deque()    

    dq.append(0)

    done = [-1 for _ in range(n)]

    done[0] = 1 

    while len(dq)>0:

        v = dq.popleft()

        for nx in to[v]:

            if done[nx] != -1:

                continue

            done[nx] = v

            dq.append(nx)



    print('Yes')

    for i in done[1:]:

        print((i+1))

if __name__ == '__main__':

    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque


def main():
    N, M = list(map(int, readline().split()))
    to = [[] for _ in range(N)]
    for _ in range(M):
        a, b = list(map(int, readline().split()))
        to[a - 1].append(b - 1)
        to[b - 1].append(a - 1)
    dq = deque()
    dq.append(0)
    done = [0 for _ in range(N)]
    done[0] = 1
    ans = [0 for _ in range(N)]
    while len(dq) > 0:
        v = dq.popleft()
        for nx in to[v]:
            if done[nx]:
                continue
            ans[nx] = v
            done[nx] = 1
            dq.append(nx)
    print("Yes")
    for i in ans[1:]:
        print((i + 1))


if __name__ == "__main__":
    main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque


def main():
    n, m = list(map(int, readline().split()))
    to = [[] for _ in range(n)]
    for _ in range(m):
        a, b = list(map(int, readline().split()))
        a -= 1
        b -= 1
        to[a].append(b)
        to[b].append(a)
    dq = deque()
    dq.append(0)
    done = [-1 for _ in range(n)]
    done[0] = 1
    while len(dq) > 0:
        v = dq.popleft()
        for nx in to[v]:
            if done[nx] != -1:
                continue
            done[nx] = v
            dq.append(nx)
    print("Yes")
    for i in done[1:]:
        print((i + 1))


if __name__ == "__main__":
    main()

-    N, M = list(map(int, readline().split())) -    to = [[] for _ in range(N)] -    for _ in range(M): +    n, m = list(map(int, readline().split())) +    to = [[] for _ in range(n)] +    for _ in range(m): -        to[a - 1].append(b - 1) -        to[b - 1].append(a - 1) +        a -= 1 +        b -= 1 +        to[a].append(b) +        to[b].append(a) -    done = [0 for _ in range(N)] +    done = [-1 for _ in range(n)] -    ans = [0 for _ in range(N)] -            if done[nx]: +            if done[nx] != -1: -            ans[nx] = v -            done[nx] = 1 +            done[nx] = v -    for i in ans[1:]: +    for i in done[1:]: