process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", input => {
  const splited = input.split("\n");
  const nums = splited[0].split(" ");
  const N = Number(nums[0]);
  const M = Number(nums[1]);
  const roomDefs = splited
    .filter((val, index) => index !== 0)
    .map(element => element.split(" ").map(num => Number(num)));
  const result = getResult(N, M, roomDefs);
  console.log(result);
});

const getResult = (N, M, roomDefs) => {
  let connected = [{ roomNo: 1, priority: 0 }];
  const getNewConnectedRooms = base => {
    return roomDefs
      .filter(def => def.includes(base))
      .filter(def => {
        const pairRoom = def[0] === base ? def[1] : def[0];
        return !connected.some(val => val.roomNo === pairRoom);
      })
      .map(def => (def[0] === base ? def[1] : def[0]));
  };
  const update = base => {
    const baseDef = connected.find(c => c.roomNo === base);
    const newPriority = baseDef.priority + 1;
    const newDescoveries = getNewConnectedRooms(base);
    if (newDescoveries.length > 0) {
      connected = connected.concat(
        newDescoveries.map(d => ({
          roomNo: d,
          priority: newPriority,
          connected: base
        }))
      );
      newDescoveries.forEach(d => update(d));
    }
  };
  const optimize = () => {
    let isChanged = false;
    do {
      connected.forEach(c => {
        const roomNo = c.roomNo;
        if (roomNo === 1) {
          return;
        }
        const currentPriority = c.priority;
        const connectedRoom = roomDefs
          .filter(def => def.includes(roomNo))
          .map(def => {
            const pair = def[0] === roomNo ? def[1] : def[0];
            return connected.find(pairDef => pairDef.roomNo === pair);
          })
          .sort((r1, r2) => r1.priority - r2.priority)[0]; // ここは最低一件とれるはず

        if (connectedRoom.priority < currentPriority - 1) {
          c.priority = connectedRoom.priority + 1;
          c.connected = connectedRoom.roomNo;
          isChanged = true;
        }
      });
    } while (isChanged);
  };

  update(1);

  if (connected.length !== N) {
    return "No";
  }

  optimize();

  return connected
    .sort((r1, r2) => r1.roomNo - r2.roomNo)
    .map((val, index) => (index === 0 ? "Yes" : val.connected))
    .join("\n");
};
