結果

問題 No.583 鉄道同好会
ユーザー pekempeypekempey
提出日時 2017-10-28 03:16:37
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 938 bytes
コンパイル時間 11,330 ms
コンパイル使用メモリ 189,568 KB
実行使用メモリ 71,840 KB
最終ジャッジ日時 2024-05-01 18:38:28
合計ジャッジ時間 16,683 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,760 KB
testcase_01 AC 2 ms
6,812 KB
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 223 ms
22,016 KB
testcase_12 AC 314 ms
26,112 KB
testcase_13 AC 316 ms
26,112 KB
testcase_14 AC 322 ms
27,264 KB
testcase_15 AC 414 ms
31,232 KB
testcase_16 AC 905 ms
54,784 KB
testcase_17 AC 1,151 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:16: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."
   |
16 |                       then let reachable = dfs ((head . head) g) [] g
   |                                                  ^^^^

Main.hs:16: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."
   |
16 |                       then let reachable = dfs ((head . head) g) [] g
   |                                                         ^^^^

Main.hs:23:39: 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."
   |
23 |     adj1 = map last . filter ((==u) . head) $ g
   |                                       ^^^^

Main.hs:24:16: 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."
   |
24 |     adj2 = map head . filter ((==u) . last) $ g
   |                ^^^^
[2 of 2] Linking a.out

ソースコード

diff #

import Data.List
import Control.Applicative
import Debug.Trace

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) [] g
                           in (sort . nub) reachable == (sort . nub . concat) g
                      else False

dfs :: Int -> [Int] -> [[Int]] -> [Int]
dfs u vis g = foldl' f (u:vis) (adj1 ++ adj2)
  where
    adj1 = map last . filter ((==u) . head) $ g
    adj2 = map head . filter ((==u) . last) $ g

    f :: [Int] -> Int -> [Int]
    f vis v
      | v `elem` vis = vis
      | otherwise    = dfs v vis g
0