Created
October 27, 2013 04:21
-
-
Save mnstrspeed/7177944 to your computer and use it in GitHub Desktop.
Haskell solution (hopefully...) to BAPC 2013 Problem F
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
minimalize [] _ = [] | |
minimalize remaining ((a, b) : xs) | |
| elem a remaining || elem b remaining = | |
(a, b) : minimalize (filter (\x -> x /= a && x /= b) remaining) xs | |
| otherwise = minimalize remaining xs | |
readInts = getLine >>= \line -> return $ map read $ words $ line | |
readEdge = readInts >>= \[a, b] -> return (a, b) | |
run = do | |
[cities, pilots] <- readInts | |
edges <- replicateM pilots readEdge | |
print $ length $ minimalize [1..cities] edges | |
main :: IO () | |
main = readLn >>= \n -> replicateM_ n run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment