output_description: If there is no way to place signposts satisfying the objective, print `No`.
  
  Otherwise, print N lines. The first line should contain `Yes`, and the i-th
  line (2 \leq i \leq N) should contain the integer representing the room
  indicated by the signpost in Room i.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      A_1 B_1
      :
      A_M B_M
attempt: from collections import defaultdict as dd
  
  N, M = map(int, input().split())
  A2B = dd(list)
  B2A = dd(list)
  for a in range(M):
      A, B = input().split()
      A2B[A].append(B)
      B2A[B].append(A)
  
  # 探索するノードの一覧
  nodes_seek = set([str(x) for x in range(1, N + 1)])
  
  # 探索したノードの一覧
  disc_nodes = set([])
  
  # 各ノードの最短経路を保管する辞書
  shortest_path = dd(list)
  # 各ノードの暫定の最短ホップ数を保管する辞書
  shops = dd(int)
  # 各ノードの最短経路における、手前のノードを記憶する辞書
  sprev = dd(str)
  
  # ノード1から順に探索
  ## ノード1に入った⇒ 隣接する部屋のリスト一覧を取得
  nxt_nodes = dd(list)
  nxt_nodes["1"] = A2B["1"]
  nxt_nodes["1"] += B2A["1"]
  
  ## ノード1への距離を0として記入
  shops["1"] = 0
  shortest_path["1"] = []
  sprev["1"] = []
  disc_nodes.add("1")
  
  # 取得した隣接リストを使う（が、幅優先で考える）
  
  
  count = 0
  
  while len(disc_nodes) < N:
      # 現在の隣接リストをあたり、次の隣接ノードのリストを作成する
      nnxt_nodes = dd(list)
      for key in nxt_nodes.keys():
          ## 現在の隣接リストから、すでに見つかったノードを省く
          tnxt_nodes = set(nxt_nodes[key]) - disc_nodes
  
          for n in tnxt_nodes:
              # 現在の隣接リストで見つかったノードについて、
              ## 手前のノードとして、現在のKeyを記入
              shops[n] = shops[key] + 1
              sprev[n] = str(key)
  
              ## 探索済みノードとして追記
              disc_nodes.add(n)
  
              ## 次の隣接リストを取得、記載する
              nnxt_nodes[n] += A2B[n]
              nnxt_nodes[n] += B2A[n]
      nxt_nodes = nnxt_nodes
  
  #     count += 1
  #     if count >100:
  #         break
  
  ans = "Yes"
  
  # print(" ----------------------- ")
  
  # for i in range(1,N+1):
  #     print("i:",i)
  #     print("-- shops --")
  #     print(shops[str(i)])
  
  #     print("-- sprev --")
  #     print(sprev[str(i)])
  
  
  # print("disc_nodes")
  # print(disc_nodes)
  
  for i in range(1, N + 1):
      if i == 1:
          print(ans)
      else:
          #         print(i,sprev[str(i)])
          print(sprev[str(i)])
  
problem_description: Statement
  
  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.
samples: [{"input": "4 4\n    1 2\n    2 3\n    3 4\n    4 2", "output": "Yes\n    1\n    2\n    2\n    \n\nIf we place the signposts as described in the sample output, the following\nhappens:\n\n  * Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \\to 1. This is the minimum number of passages possible.\n  * Starting in Room 3, you will reach Room 1 after traversing two passages: (3) \\to 2 \\to 1. This is the minimum number of passages possible.\n  * Starting in Room 4, you will reach Room 1 after traversing two passages: (4) \\to 2 \\to 1. This is the minimum number of passages possible.\n\nThus, the objective is satisfied.\n\n* * *"}, {"input": "6 9\n    3 4\n    6 1\n    2 4\n    5 3\n    4 6\n    1 5\n    6 2\n    4 5\n    5 6", "output": "Yes\n    6\n    5\n    5\n    1\n    1\n    \n\nIf there are multiple solutions, any of them will be accepted."}]