import Control.Applicative import Control.Monad import Control.Monad.ST import Data.List import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.Char (isSpace) import Data.Vector.Unboxed (Vector, (!)) import qualified Data.Vector.Unboxed as V import Data.Vector.Unboxed.Mutable (IOVector, STVector) import qualified Data.Vector.Unboxed.Mutable as VM main :: IO () main = do [n, k, x] <- f solve n <$> replicateM (x-1) f <*> (B.getLine >> replicateM (k-x) f) <*> f >>= putStrLn where f = readil B.readInt <$> B.getLine solve :: Int -> [[Int]] -> [[Int]] -> [Int] -> String solve n hs ts cs = runST $ do hv <- V.thaw $ V.fromList [1..n] :: ST s (STVector s Int) forM_ hs $ \[a,b] -> do VM.swap hv (a-1) (b-1) tv <- V.thaw $ V.fromList cs :: ST s (STVector s Int) forM_ (reverse ts) $ \[a,b] -> do VM.swap tv (a-1) (b-1) xs <- foldM (f hv tv) [] [n,n-1 .. 1] return . unwords . map show $ xs where f hv tv ls i = do x <- VM.read hv (i-1) y <- VM.read tv (i-1) if x == y then return ls else return (i:ls) readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')