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 Haskell (GHC 8.8.3) (judge verdict: Time Limit Exceeded)

import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS --(ByteString, getLine, readInt, words)
import qualified  Data.ByteString as B
import Data.Array.Unboxed (UArray)
import Data.Array (Array, listArray, array, (!), (//), indices, elems, assocs) 

import Data.Bits (shift, shiftR, (.|.), (.&.)) --  bits `shift` 1
import Data.List (sort, sortOn, permutations)
import Data.Char --(toLower, toUpper, isUpper)
import Data.Ord -- Data.Ord.Down 
import Data.Array.ST  --(newListArray, runSTUArray, newArray, writeArray, readArray)
import Data.Array.IO 
import Control.Monad.ST (ST)
import Data.List.Extra (snoc)
import Data.Time (getCurrentTime, diffUTCTime)


import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector.Unboxed         as V --(fromList, !, replicateM)
import qualified Data.Vector.Unboxed.Mutable as VM --(new, read, write, swap, modify, unsafeWrite, unsafeRead, STVector, IOVector)
-- import Data.Time.LocalTime


-- example: putStrLn show 123 ++ "and" ~~ 456 ++ "or" ~~ 789
(~~) :: Show a => String -> a -> String
a ~~ b = a ++ show b

bslen = BS.length -- o(1)
bshd = BS.head -- o(1)
bstl = BS.tail -- o(1)
bslst = BS.last -- o(1)
bsini = BS.init -- o(1)
charToInt n = ord n - ord '0'
readi n = read n :: Int

bsToInt :: BS.ByteString -> Int
bsToInt = fst . fromJust . BS.readInt
getInt = bsToInt <$> BS.getLine

bsToInts :: BS.ByteString -> [Int]
bsToInts = map bsToInt . BS.words 
getInts = bsToInts <$> BS.getLine

getLines :: Int -> IO [BS.ByteString]
getLines n = replicateM n BS.getLine

getLinesToInts :: Int -> IO [Int]
getLinesToInts n = replicateM n $ bsToInt <$> BS.getLine

--Vector (one dimensional array)
getLinesToVectorInts :: Int -> IO (V.Vector Int)
getLinesToVectorInts n = V.replicateM n $ bsToInt <$> BS.getLine

getLinesToVector_TupleIntInt :: Int -> IO (V.Vector (Int, Int))
getLinesToVector_TupleIntInt n =
    V.replicateM n $ do
        [a,b] <- getInts
        return (a,b)

mapPutStrLn :: [String] -> IO()
mapPutStrLn = mapM_ putStrLn

--Data.List.sortOn [0..9] -> [9..0]
testSortDown = print $ sortOn Data.Ord.Down [0..9]


-----------------------------------------------------------------------
------------------------------------------------------------------------

-----------------------------------------------------------------------
-----------------------------------------------------------------------
-- Data.Array      Immutable non-strict(lazy?) arrays
-- make array
ary1 :: Array Int String
ary1 = array (1,3) [(1, "contain1"), (2, "contain2"), (3, "contain3")]

ary2 :: Array Int Int
ary2 = listArray (1, 10^10) [1..10^10]

--(!) : read an element ... o(1)
ary1_3 = ary1 ! 3 -- (3,"contain3")

-- (//) : overwrite elements ... o(n)
-- actually, deep copy
ary1write :: Array Int String
ary1write = ary1 // [(1, "contain1_modified"), (3, "contain3_modified")]

-- bounds  ary1 -> (1,3)
-- indices ary1 -> [1,2,3]
-- elems   ary1 -> ["contain1", "contain2", "contain3"]



-----------------------------------------------------------------------
-----------------------------------------------------------------------
-- Mutable Arrays
-- Data.Array.ST (newListArray, newArray, writeArray, readArray, runSTUArray)
-- You can extract STUArray to UArray (Data.Array.Unboxed)

uary1 :: UArray Int Bool -- UArray is Immutable!
uary1 = runSTUArray $ stuaryInitVal

stuaryInitVal  :: ST s (STUArray s Int Bool) -- Mutable!
stuaryUndefVal :: ST s (STUArray s Int Bool)
stuaryFromList :: ST s (STUArray s Int Int)
stuaryInitVal  = newArray     (1, 9)  True
stuaryUndefVal = newArray_    (1, 9)
stuaryFromList = newListArray (1, 9) [0..]

-- readArray and writeArray ... o(1) 
-- readUary  = readArray uary1 1
-- writeUary = writeArray uary1 1 True
readStu = stuaryInitVal >>= (`readArray` 1)
writeStu = stuaryInitVal >>= (\x -> writeArray x 1 False)


-- Data.Array.IO (newListArray,..)
-- You CAN'T extract IOUArray 
iouaryInitVal  :: IO (IOUArray Int Int) -- Mutable!
iouaryUndefVal :: IO (IOUArray Int Int)
iouaryFromList :: IO (IOUArray Int Int)
iouaryInitVal  = newArray     (1, 9) 1 
iouaryUndefVal = newArray_    (1, 9)
iouaryFromList = newListArray (1, 9) [0..]

-- readArray and writeArray ... o(1) 
readIou = iouaryInitVal >>= (`readArray` 1)
writeIou = iouaryInitVal >>= (\x -> writeArray x 1 100)


newints :: Int -> Int -> Int -> IO(IOUArray Int Int)
newints start n = newArray (start, n)

rd :: IOUArray Int Int -> Int -> IO Int
rd = readArray

wt :: IOUArray Int Int -> Int -> Int -> IO()
wt = writeArray

--example: effect  (newArray (1, 3) 0)  3 (+100)   ->   array [(1,0), (2,0), (3,100)]
effect :: IOUArray Int Int -> Int -> (Int -> Int) -> IO()
effect ary i operator = (operator <$> readArray ary i) >>= writeArray ary i

-----------------------------------------------------------------------
-----------------------------------------------------------------------

-- Data.Set
setFromList    = Set.fromList [1,1,4,2,3,3,4,4]      -- -> set [1,2,3,4],       o(n*log n)
setFromAscList = Set.fromAscList [1,1,4,2,2,3,3,4,4] -- -> set [1,  4,  2,3,4], o(n)
setSize        = Set.size setFromList                -- -> 4,                   o(1)
setToList      = Set.toList setFromList              -- -> [1,2,3,4],           o(n)
-- toAscList, toDecList



bfs :: [(Int,Int)] -> VM.IOVector Int -> [(Int,Int)] -> VM.IOVector Int -> Int -> Int -> IO ()
-- n-1 rooms is done
bfs _ _ _ _ 1 _
    = return ()

-- go to next depth
bfs [] depths rests exits k d
    = -- do putStrLn $ "next"
        bfs rests depths [] exits k (d+1)

bfs ((a,b):abs) depths rests exits k d
    = do
    depth_a <- VM.read depths a
    depth_b <- VM.read depths b
    exit_b <- VM.read exits b
    exit_a <- VM.read exits a
    if depth_a /= d && depth_b /= d then
        bfs abs depths ((a,b):rests) exits k d
    else if depth_a == d && exit_b == 0 then do
        VM.write depths b (d+1)
        VM.write exits b a
        bfs abs depths rests exits (k-1) d
    else if depth_b == d && exit_a == 0 then do
        VM.write depths a (d+1)
        VM.write exits a b
        bfs abs depths rests exits (k-1) d
    else -- not required path -> discard it
        bfs abs depths rests exits k d

main :: IO ()
main = do
    [n,m] <- getInts
    abs <- replicateM m $ do 
        [a,b] <- getInts
        return (a,b)
    exits <- VM.new (n+1) :: IO(VM.IOVector Int)
    depths <- VM.new (n+1) :: IO(VM.IOVector Int)
    VM.set exits 0
    VM.set depths 0
    VM.write depths 1 1
    bfs abs depths [] exits n 1  
    putStrLn "Yes"
    mapM_ (\i ->
        VM.read exits i >>= print) [2..n]