Problem:
Score: 400 points

Problem 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.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq M \leq 2 \times 10^5

1 \leq A_i, B_i \leq N\ (1 \leq i \leq M)

A_i \neq B_i\ (1 \leq i \leq M)

One can travel between any two rooms by traversing passages.

Input

Input is given from Standard Input in the following format:

N M
A_1 B_1
:
A_M B_M

Output

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.

Sample Input 1

4 4
1 2
2 3
3 4
4 2

Sample Output 1

Yes
1
2
2

If we place the signposts as described in the sample output, the following happens:

Starting in Room 2, you will reach Room 1 after traversing one passage: (2) \to 1. This is the minimum number of passages possible.

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.

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.

Thus, the objective is satisfied.

Sample Input 2

6 9
3 4
6 1
2 4
5 3
4 6
1 5
6 2
4 5
5 6

Sample Output 2

Yes
6
5
5
1
1

If there are multiple solutions, any of them will be accepted.

Solution in Rust (1.42.0) (judge verdict: Wrong Answer)

#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::slice::*;

fn main() {
    let (r, w, e) = (stdin(), stdout(), stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());
    // =============================================== //
    let (n, m): (usize, usize) = (io.read(), io.read());
    let mut g: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..m {
        let (a, b): (usize, usize) = (io.read(), io.read());
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
    }
    let inf = 5 << 40;
    let ans: Vec<(usize, usize)> = vec![(inf, 0); n];
    let mut gg: G = G { g: g, ans: ans };
    gg.dfs(0, 0, 0);
    //io.debug(gg.ans)
    let ans = gg.ans;
    for i in 1..n {
        println!("{}", ans[i].1 + 1);
    }

    // let mut q: Vec<(usize, usize, usize)> = Vec::new();
    // let mut ans: Vec<isize> = vec![0; n];
    // q.push((0, 0, 0));
    // ans[0] = 0;
    // let mut visited = vec![false; n];
    // visited[0] = true;
    // let inf = 3 << 30;
    // let mut ans2: Vec<(usize, usize)> = vec![(inf, 0); n];
    // // bfs
    // while let Some(got) = q.pop() {
    //     //
    //     let now = got.0;
    //     let depth = got.1;
    //     let prev = got.2;
    //     ans2[now] = min(ans2[now], (depth, prev));
    //     ans[now] = prev as isize;

    //     for &nxt in g[now].iter() {
    //         if visited[nxt] {
    //             continue;
    //         }
    //         //   println!("now = {}, nxt = {}, depth = {}", now + 1, nxt + 1, depth);
    //         //visited[nxt] = true;
    //         q.push((nxt, depth + 1, now));
    //     }
    //     visited[now] = true;
    // }
    // println!("Yes");
    // for i in 1..n {
    //     println!("{}", ans2[i].1 + 1);
    // }
}
struct G {
    g: Vec<Vec<usize>>,
    ans: Vec<(usize, usize)>,
}
impl G {
    fn dfs(&mut self, depth: usize, now: usize, prev: usize) {
        if self.ans[now].0 > depth {
            self.ans[now].0 = depth;
            self.ans[now].1 = prev;
        } else {
            return;
        }

        let len = self.g[now].len();
        //println!("{}", len);
        for i in 0..len {
            self.dfs(depth + 1, self.g[now][i], now);
        }
    }
}

// IO
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug ) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
}