diff --git a/12_graph.hs b/12_graph.hs index f4308df..80d87c6 100644 --- a/12_graph.hs +++ b/12_graph.hs @@ -1,13 +1,14 @@ import Data.List.Split (splitOn) -import Data.Graph (graphFromEdges, reachable, scc) +import Data.Graph (reachable, scc) +import Data.Array (array) -parseLine :: String -> (Int, Int, [Int]) +parseLine :: String -> (Int, [Int]) parseLine str = let src : dests : [] = splitOn " <-> " str - in (read src, read src, map read $ splitOn ", " dests) + in (read src, map read $ splitOn ", " dests) main :: IO () main = do - (graph, _, _) <- fmap (graphFromEdges . map parseLine . lines) $ readFile "12.txt" + graph <- fmap (array (0, 1999) . map parseLine . lines) $ readFile "12.txt" print $ length $ reachable graph 0 print $ length $ scc graph \ No newline at end of file