Scanf.scanf "%d %d" (fun n m ->
    let nei = Array.make n [] in
    for i = 1 to m do
        Scanf.scanf " %d %d" (fun a b ->
            let a = a - 1 in let b = b - 1 in
            nei.(a) <- b :: nei.(a);
            nei.(b) <- a :: nei.(b);
        )
    done;

    let light = Array.make n (-1) in
    let dist = Array.make n 1000000000 in
    let () = light.(0) <- 0 in
    let () = dist.(0) <- 0 in

    let module S = Set.Make (struct type t = int * int let compare = compare end) in

    let rec dijkstra set =
        if S.is_empty set then () else (
            let (cost, node) as elt = S.min_elt set in
            let set = S.remove elt set in
            let set = List.fold_left (fun set next ->
                if dist.(next) > cost + 1 then (
                    dist.(next) <- cost + 1;
                    light.(next) <- node;
                    S.add (cost + 1, next) set
                ) else set
            ) set nei.(node)
            in
            dijkstra set
        )
    in
    dijkstra (S.singleton (0, 0));
    let rec loop i =
        if i = n then true else
            if light.(i) < 0 then false else
                loop (i + 1)
    in
    if loop 1 then (
        print_endline "Yes";
        for i = 1 to n - 1 do
            Printf.printf "%d\n" (light.(i) + 1)
        done
    ) else print_endline "No"
)