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: import heapq
  from collections import deque
  
  
  class Graph:
      def __init__(self, v, edgelist, w_v=None, directed=False):
          super().__init__()
          self.v = v
          self.w_e = [{} for _ in [0] * self.v]
          self.neighbor = [[] for _ in [0] * self.v]
          self.w_v = w_v
          self.directed = directed
  
          for i, j, w in edgelist:
              self.w_e[i][j] = w
              self.neighbor[i].append(j)
  
      def dijkstra(self, v_n):
          d = [float("inf")] * self.v
          d[v_n] = 0
          prev = [-1] * self.v
  
          queue = []
          for i, d_i in enumerate(d):
              heapq.heappush(queue, (d_i, i))
  
          while len(queue) > 0:
              d_u, u = queue.pop()
              if d[u] < d_u:
                  continue
              for v in self.neighbor[u]:
                  alt = d[u] + self.w_e[u][v]
                  if d[v] > alt:
                      d[v] = alt
                      prev[v] = u
                      heapq.heappush(queue, (alt, v))
  
          return d, prev
  
      def warshallFloyd(self):
          d = [[10**18] * self.v for _ in [0] * self.v]
          for i in range(self.v):
              d[i][i] = 0
  
          for i in range(self.v):
              for j in self.neighbor[i]:
                  d[i][j] = self.w_e[i][j]
  
          for i in range(self.v):
              for j in self.neighbor[i]:
                  d[i][j] = self.w_e[i][j]
  
          for k in range(self.v):
              for i in range(self.v):
                  for j in range(self.v):
                      check = d[i][k] + d[k][j]
                      if d[i][j] > check:
                          d[i][j] = check
          return d
  
      def prim(self):
          gb = GraphBuilder(self.v, self.directed)
  
          queue = []
          for i, w in self.w_e[0].items():
              heapq.heappush(queue, (w, 0, i))
          rest = [True] * self.v
          rest[0] = False
  
          while len(queue) > 0:
              w, i, j = heapq.heappop(queue)
              if rest[j]:
                  gb.addEdge(i, j, w)
                  rest[j] = False
                  for k, w in self.w_e[j].items():
                      if rest[k]:
                          heapq.heappush(queue, (w, j, k))
  
          return gb
  
      def bfs(self, vartex=0):
          todo = [True] * self.v
          queue = deque([vartex])
          while len(queue) > 0:
              v = queue.popleft
              todo[v] = False
              yield v
              for v_i in self.neighbor[v]:
                  if todo[v_i]:
                      queue.append(v_i)
  
      def dfs(self, vartex=0):
          seen = [False] * self.v
  
          def recdfs(v):
              seen[vartex] = True
              for next_v in self.neighbor[vartex]:
                  if seen[next_v]:
                      continue
                  recdfs(next_v)
  
  
  class Tree:
      def __init__(self, v, e):
          pass
  
  
  class GraphBuilder:
      def __init__(self, v, directed=False, edge=None, weights=None):
          self.v = v
          self.directed = directed
          self.edge = []
          self.weights = []
          if edge is not None:
              self.addEdges(edge)
          if weights is not None:
              self.addVartex(weights)
  
      def addEdge(self, i, j, w=1):
          if not self.directed:
              self.edge.append((j, i, w))
          self.edge.append((i, j, w))
  
      def addEdges(self, edgelist, weight=True):
          if weight:
              if self.directed:
                  for i, j, w in edgelist:
                      self.edge.append((i, j, w))
              else:
                  for i, j, w in edgelist:
                      self.edge.append((i, j, w))
                      self.edge.append((j, i, w))
          else:
              if self.directed:
                  for i, j in edgelist:
                      self.edge.append((i, j, 1))
              else:
                  for i, j in edgelist:
                      self.edge.append((i, j, 1))
                      self.edge.append((j, i, 1))
  
      def addVartex(self, weights):
          if len(weights) != self.v:
              return
          self.weights.extend(weights)
  
      def addAdjMat(self, mat):
          for i, mat_i in enumerate(mat):
              for j, w in enumerate(mat_i):
                  self.edge.append((i, j, w))
  
      def buildTree(self):
          pass
  
      def buildGraph(self):
          return Graph(self.v, self.edge, directed=self.directed)
  
  
  def main():
      n, m = tuple([int(t) for t in input().split()])
      edge = []
  
      for i in range(m):
          a, b = tuple([int(t) for t in input().split()])
          edge.append((a - 1, b - 1, 1))
  
      gb = GraphBuilder(n, edge=edge)
      g = gb.buildGraph()
  
      queue = deque([0])
      root = [-1] * n
      checked = [False] * n
      while len(queue) > 0:
          p = queue.popleft()
          if checked[p]:
              continue
          checked[p] = True
          for q in g.neighbor[p]:
              root[q] = p + 1
              queue.append(q)
  
      if all(checked):
          print("Yes")
          for i in root[1:]:
              print(i)
  
  
  if __name__ == "__main__":
      main()
  
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."}]