Created
April 12, 2017 15:28
-
-
Save ifserge/6d2982b3a63e9002c094035d735eea56 to your computer and use it in GitHub Desktop.
TL solution for http://codeforces.com/contest/796/problem/B?locale=en
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.IO | |
import Control.Monad | |
import Control.Applicative | |
import Data.List | |
import qualified Data.Set as S | |
parseInt :: String -> Int | |
parseInt x = read x | |
solve :: Int -> [(Int,Int)] -> S.Set Int -> Int | |
solve x [] holes = x | |
solve x ((a,b):op) holes | S.member x holes = x | |
| x == a = if (S.member b holes) then b else solve b op holls | |
| x == b = if (S.member a holes) then a else solve a op holls | |
| otherwise = solve x op holls | |
main :: IO () | |
main = do | |
s0 <- getLine | |
let n = parseInt ((words s0)!!0) | |
let m = parseInt ((words s0)!!1) | |
let k = parseInt ((words s0)!!2) | |
s1 <- getLine | |
let holes = S.fromList $ map parseInt (words s1) | |
s3 <- replicateM k getLine | |
let ops = map (\s -> let ss=words s in ((parseInt $ head ss),(parseInt $ ss!!1))) s3 | |
putStrLn $ show $ solve 1 ops holes | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment