import Control.Applicative import Control.Monad import Control.Monad.ST import Debug.Trace import Data.List hiding (insert) import Data.Array import Data.Set (Set, fromList, toList, insert, member, empty) import qualified Data.Set as S import Data.Array.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] es = let g = toArray n es deg = map length . elems $ g in if (all even) deg || (length . filter odd) deg == 2 then let reachable = dfs ((head . head) es) S.empty g in reachable == (fromList . concat) es 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 -> Set Int -> Array Int [Int] -> Set Int dfs u vis g = foldl' f (insert u vis) (g ! u) where f :: Set Int -> Int -> Set Int f vis v | member v vis = vis | otherwise = dfs v vis g