Submission #286814


Source Code Expand

Copy
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Applicative
import           Control.Monad
import           Data.Vector         ((!))
import qualified Data.Vector         as V

main :: IO ()
main = do
  ([n, x] :: [Int]) <- map read . words <$> getLine
  (h :: [Int]) <- map read . words <$> getLine

  (es :: [[Int]]) <- replicateM (n - 1) $ map read . words <$> getLine

  let g :: V.Vector [Int]
      g = V.accum (flip (:)) (V.replicate n [])
          $ concat [ [(a-1, b-1), (b-1, a-1)] | [a, b] <- es ]

      hv :: V.Vector Int
      hv = V.fromList h

      solve cur par
        = sum
          [ solve c cur + 2
          | c <- g!cur
          , c /= par
          , cnt c cur > 0
          ]

      cnt cur par
        = (hv!cur) +
          sum
          [ cnt c cur
          | c <- g!cur
          , c /= par
          ]

  print $ solve (x-1) (-1)

  return ()

Submission Info

Submission Time
Task B - ツリーグラフ
User tanakh
Language Haskell (GHC 7.4.1)
Score 100
Code Size 933 Byte
Status AC
Exec Time 38 ms
Memory 1948 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 2
AC × 20
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_line01.txt, subtask1_line02.txt, subtask1_line03.txt, subtask1_line04.txt, subtask1_line05.txt, subtask1_line06.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_random06.txt, subtask1_random07.txt, subtask1_random08.txt, subtask1_special01.txt, subtask1_special02.txt, subtask1_special03.txt, subtask1_special04.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 32 ms 1440 KB
subtask0_sample_02.txt AC 30 ms 1440 KB
subtask1_line01.txt AC 29 ms 1312 KB
subtask1_line02.txt AC 32 ms 1948 KB
subtask1_line03.txt AC 32 ms 1940 KB
subtask1_line04.txt AC 35 ms 1876 KB
subtask1_line05.txt AC 32 ms 1948 KB
subtask1_line06.txt AC 38 ms 1948 KB
subtask1_random01.txt AC 33 ms 1900 KB
subtask1_random02.txt AC 31 ms 1900 KB
subtask1_random03.txt AC 33 ms 1948 KB
subtask1_random04.txt AC 32 ms 1944 KB
subtask1_random05.txt AC 33 ms 1944 KB
subtask1_random06.txt AC 34 ms 1944 KB
subtask1_random07.txt AC 32 ms 1944 KB
subtask1_random08.txt AC 32 ms 1904 KB
subtask1_special01.txt AC 30 ms 1444 KB
subtask1_special02.txt AC 32 ms 1944 KB
subtask1_special03.txt AC 33 ms 1900 KB
subtask1_special04.txt AC 32 ms 1904 KB