import Data.List import Control.Applicative import Debug.Trace import Data.Array import Data.Array.ST import Control.Monad import Control.Monad.ST main :: IO () main = solve <$> (map read . words <$> getLine) <*> (map (map read . words) . lines <$> getContents) >>= putStrLn . yesno yesno :: Bool -> String yesno True = "YES" yesno False = "NO" solve :: [Int] -> [[Int]] -> Bool solve [n, m] [] = True solve [n, m] g = let deg = (map length . group . sort . concat) g in if (all even) deg || (length . filter odd) deg == 2 then let reachable = dfs ((head . head) g) [] (toArray n g) in (sort . nub) reachable == (sort . nub . concat) g else False toArray :: Int -> [[Int]] -> Array Int [Int] toArray n es = runST $ do g <- newArray (0, n-1) [] :: ST s (STArray s Int [Int]) forM_ es $ \[x, y] -> do readArray g x >>= writeArray g x . (y:) readArray g y >>= writeArray g y . (x:) freeze g dfs :: Int -> [Int] -> Array Int [Int] -> [Int] dfs u vis g = foldl' f (u:vis) (g ! u) where f :: [Int] -> Int -> [Int] f vis v | v `elem` vis = vis | otherwise = dfs v vis g