Skip to content

Instantly share code, notes, and snippets.

@mnstrspeed
Created October 27, 2013 04:21
Show Gist options
  • Save mnstrspeed/7177944 to your computer and use it in GitHub Desktop.
Save mnstrspeed/7177944 to your computer and use it in GitHub Desktop.
Haskell solution (hopefully...) to BAPC 2013 Problem F
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