blob: c0baabe52c1a6409dc133706759c08e97ed8f0d1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -Wno-x-partial #-}
module M where
import Control.Monad.ST
import Data.Array.ST
import Data.Array.Unboxed
bfs :: Array Int [Int] -> ST s (STArray s Int ())
bfs g = do
vis :: STArray s Int () <- newArray (bounds g) ()
ch :: STArray s Int () <- newArray (bounds g) ()
let go [] = pure () :: ST s ()
go q = do
flip mapM_ q $ \u -> do
readArray vis (head (g!u))
readArray ch u
writeArray ch u ()
go []
go []
pure ch
|