Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Applicative
- import Control.Monad
- import Data.Bits
- rule :: [Int] -> (Int, Int)
- rule x = (x !! 0, x !! 1)
- hasEdge :: Int -> Int -> [(Int, Int)] -> Bool
- hasEdge s v list = foldr edge False list
- where edge t b = b || (fst t) == v && testBit s (snd t)
- func :: Int -> Int -> [(Int, Int)] -> Int
- func s n t = if s == 1 then 1 else sum $ map (\a -> if (testBit s a) && not (hasEdge s a t) then func (clearBit s a) n t else 0) [1..n]
- main :: IO ()
- main = do
- [n, m] <- map read . words <$> getLine
- t <- replicateM m $ rule . map read . words <$> getLine
- let b = foldl (setBit) (bit 0) [1..n] :: Int
- putStrLn $ show $ func b n t
- return ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement