Submission #35132576


Source Code Expand

import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Sequence as Sq

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, x, y] <- getIntList
    uv <- replicateM (n-1) $ do
        [u, v] <- getIntList
        return (u-1, v-1)

    let edges = V.create $ do
            vec <- VM.replicate n []
            forM_ uv $ \(a,b) -> do
                VM.modify vec (a:) b
                VM.modify vec (b:) a
            return vec

    let result = VU.create $ do
            vec <- VUM.replicate n ((-1) :: Int)
            let go Sq.Empty = return ()
                go ((p, this) Sq.:<| qs) = do
                    VUM.write vec this p
                    go . foldl (Sq.|>) qs . map (\t -> (this, t)) $ filter (/= p) (edges V.! this)
            go (Sq.singleton (-2, x-1))
            return vec

    let path = reverse $ loop (y-1)
            where loop v | v < 0 = []
                         | otherwise = (v+1) : loop (result VU.! v)
    putStrLn . unwords $ map show path

Submission Info

Submission Time
Task C - Simple path
User pel
Language Haskell (GHC 8.8.3)
Score 300
Code Size 1377 Byte
Status AC
Exec Time 396 ms
Memory 107628 KiB

Compile Error

Loaded package environment from /home/contestant/.ghc/x86_64-linux-8.8.3/environments/default

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 27
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 7 ms 4100 KiB
example_01.txt AC 2 ms 4076 KiB
hand_00.txt AC 2 ms 3984 KiB
hand_01.txt AC 389 ms 107408 KiB
hand_02.txt AC 325 ms 107336 KiB
hand_03.txt AC 395 ms 107484 KiB
hand_04.txt AC 396 ms 107336 KiB
random_00.txt AC 386 ms 107588 KiB
random_01.txt AC 382 ms 107512 KiB
random_02.txt AC 379 ms 107588 KiB
random_03.txt AC 387 ms 107532 KiB
random_04.txt AC 390 ms 107336 KiB
random_05.txt AC 388 ms 107400 KiB
random_06.txt AC 394 ms 107400 KiB
random_07.txt AC 390 ms 107628 KiB
random_08.txt AC 389 ms 107332 KiB
random_09.txt AC 371 ms 107480 KiB
random_10.txt AC 361 ms 107500 KiB
random_11.txt AC 370 ms 107484 KiB
random_12.txt AC 394 ms 107504 KiB
random_13.txt AC 390 ms 107476 KiB
random_14.txt AC 391 ms 107504 KiB
random_15.txt AC 392 ms 107516 KiB
random_16.txt AC 388 ms 107532 KiB
random_17.txt AC 351 ms 107520 KiB
random_18.txt AC 360 ms 107512 KiB
random_19.txt AC 352 ms 107476 KiB