結果
問題 | No.583 鉄道同好会 |
ユーザー | pekempey |
提出日時 | 2017-10-28 03:35:58 |
言語 | Haskell (9.8.2) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,194 bytes |
コンパイル時間 | 3,247 ms |
コンパイル使用メモリ | 195,200 KB |
実行使用メモリ | 66,304 KB |
最終ジャッジ日時 | 2024-11-22 00:30:42 |
合計ジャッジ時間 | 11,234 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 1 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,820 KB |
testcase_09 | AC | 1 ms
6,820 KB |
testcase_10 | AC | 5 ms
6,912 KB |
testcase_11 | AC | 188 ms
22,016 KB |
testcase_12 | AC | 296 ms
26,240 KB |
testcase_13 | AC | 281 ms
26,368 KB |
testcase_14 | AC | 280 ms
27,264 KB |
testcase_15 | AC | 370 ms
31,488 KB |
testcase_16 | AC | 859 ms
54,784 KB |
testcase_17 | AC | 1,005 ms
66,048 KB |
testcase_18 | TLE | - |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) Main.hs:20:50: warning: [GHC-63394] [-Wx-partial] In the use of ‘head’ (imported from Data.List, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 20 | then let reachable = dfs ((head . head) g) [] (toArray n g) | ^^^^ Main.hs:20:57: warning: [GHC-63394] [-Wx-partial] In the use of ‘head’ (imported from Data.List, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 20 | then let reachable = dfs ((head . head) g) [] (toArray n g) | ^^^^ [2 of 2] Linking a.out
ソースコード
import Data.List import Control.Applicative import Debug.Trace import Data.Array import Data.Array.ST import Control.Monad import Control.Monad.ST main :: IO () main = solve <$> (map read . words <$> getLine) <*> (map (map read . words) . lines <$> getContents) >>= putStrLn . yesno yesno :: Bool -> String yesno True = "YES" yesno False = "NO" solve :: [Int] -> [[Int]] -> Bool solve [n, m] [] = True solve [n, m] g = let deg = (map length . group . sort . concat) g in if (all even) deg || (length . filter odd) deg == 2 then let reachable = dfs ((head . head) g) [] (toArray n g) in (sort . nub) reachable == (sort . nub . concat) g else False toArray :: Int -> [[Int]] -> Array Int [Int] toArray n es = runST $ do g <- newArray (0, n-1) [] :: ST s (STArray s Int [Int]) forM_ es $ \[x, y] -> do readArray g x >>= writeArray g x . (y:) readArray g y >>= writeArray g y . (x:) freeze g dfs :: Int -> [Int] -> Array Int [Int] -> [Int] dfs u vis g = foldl' f (u:vis) (g ! u) where f :: [Int] -> Int -> [Int] f vis v | v `elem` vis = vis | otherwise = dfs v vis g