from heapq import heappush, heappop

 

INT_MAX = 10 ** 9

 

 

def main():

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

  ab = (list(map(int, input().split())) for i in range(m))

  

  g = [[] for i in range(n+1)]

  gp = [INT_MAX] * (n+1)

  gf = [0] * (n+1)

  

  for a, b in ab:

    g[a].append(b)

    g[b].append(a)

  

  h = [(0, 1, 1)]

  

  while h:

    p, a, f = heappop(h)

    if p < gp[a]:

      gp[a] = p

      gf[a] = f

    else:

      continue

    for b in g[a]:

      heappush(h, (p + 1, b, a))

  

  r = gf[2:]

  s = 'Yes' if all(0 < i < INT_MAX for i in r) else 'No'

  print(s)

  if s == 'Yes':

    for i in r:

      print(i)

  

if __name__ == '__main__':

  main()


def main():

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

    ab = (list(map(int, input().split())) for _ in range(m))



    # 死因 graph = [[0] * (n+1) for _ in range(n+1)]

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



    for a, b in ab:

        graph[a].append(b)

        graph[b].append(a)



    from collections import deque



    q = deque()

    q.append(1)



    p = [0] * (n+1)



    while q:

        a = q.popleft()

        for b in graph[a]:

            if not p[b]:

                p[b] = a

                q.append(b)



    result = p[2:]



    is_yes = all(result)



    print(('Yes' if is_yes else 'No'))



    if is_yes:

        for r in result:

            print(r)





if __name__ == "__main__":

    main()

from heapq import heappush, heappop

INT_MAX = 10**9


def main():
    n, m = list(map(int, input().split()))
    ab = (list(map(int, input().split())) for i in range(m))
    g = [[] for i in range(n + 1)]
    gp = [INT_MAX] * (n + 1)
    gf = [0] * (n + 1)
    for a, b in ab:
        g[a].append(b)
        g[b].append(a)
    h = [(0, 1, 1)]
    while h:
        p, a, f = heappop(h)
        if p < gp[a]:
            gp[a] = p
            gf[a] = f
        else:
            continue
        for b in g[a]:
            heappush(h, (p + 1, b, a))
    r = gf[2:]
    s = "Yes" if all(0 < i < INT_MAX for i in r) else "No"
    print(s)
    if s == "Yes":
        for i in r:
            print(i)


if __name__ == "__main__":
    main()

def main():
    n, m = list(map(int, input().split()))
    ab = (list(map(int, input().split())) for _ in range(m))
    # 死因 graph = [[0] * (n+1) for _ in range(n+1)]
    graph = [[] for _ in range(n + 1)]
    for a, b in ab:
        graph[a].append(b)
        graph[b].append(a)
    from collections import deque

    q = deque()
    q.append(1)
    p = [0] * (n + 1)
    while q:
        a = q.popleft()
        for b in graph[a]:
            if not p[b]:
                p[b] = a
                q.append(b)
    result = p[2:]
    is_yes = all(result)
    print(("Yes" if is_yes else "No"))
    if is_yes:
        for r in result:
            print(r)


if __name__ == "__main__":
    main()

-from heapq import heappush, heappop - -INT_MAX = 10**9 - - -    ab = (list(map(int, input().split())) for i in range(m)) -    g = [[] for i in range(n + 1)] -    gp = [INT_MAX] * (n + 1) -    gf = [0] * (n + 1) +    ab = (list(map(int, input().split())) for _ in range(m)) +    # 死因 graph = [[0] * (n+1) for _ in range(n+1)] +    graph = [[] for _ in range(n + 1)] -        g[a].append(b) -        g[b].append(a) -    h = [(0, 1, 1)] -    while h: -        p, a, f = heappop(h) -        if p < gp[a]: -            gp[a] = p -            gf[a] = f -        else: -            continue -        for b in g[a]: -            heappush(h, (p + 1, b, a)) -    r = gf[2:] -    s = "Yes" if all(0 < i < INT_MAX for i in r) else "No" -    print(s) -    if s == "Yes": -        for i in r: -            print(i) +        graph[a].append(b) +        graph[b].append(a) +    from collections import deque + +    q = deque() +    q.append(1) +    p = [0] * (n + 1) +    while q: +        a = q.popleft() +        for b in graph[a]: +            if not p[b]: +                p[b] = a +                q.append(b) +    result = p[2:] +    is_yes = all(result) +    print(("Yes" if is_yes else "No")) +    if is_yes: +        for r in result: +            print(r)