import Data.List import Control.Applicative import Debug.Trace 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) [] g in (sort . nub) reachable == (sort . nub . concat) g else False dfs :: Int -> [Int] -> [[Int]] -> [Int] dfs u vis g = foldl' f (u:vis) (adj1 ++ adj2) where adj1 = map last . filter ((==u) . head) $ g adj2 = map head . filter ((==u) . last) $ g f :: [Int] -> Int -> [Int] f vis v | v `elem` vis = vis | otherwise = dfs v vis g