import Data.IntMap.Strict ((!)) import qualified Data.IntMap.Strict as M import qualified Data.ByteString.Char8 as B import Data.List import Data.Maybe import Control.Monad readInt = fst . fromJust . B.readInt swap i j im = M.insert j (im!i) (M.insert i (im!j) im) main = do [n,k,x] <- map read . words <$> getLine ab1s <- map (map readInt . B.words) <$> replicateM (x-1) B.getLine getLine ab2s <- map (map readInt . B.words) <$> replicateM (k-x) B.getLine cs <- map read . words <$> getLine let start = M.fromDistinctAscList (zip [1..n] [1..n]) let goal = M.fromDistinctAscList (zip [1..n] cs) putStrLn $ unwords $ map show (shuffle start ab1s goal ab2s) shuffle start ab1s goal ab2s = map succ $ findIndices id (zipWith (/=) prev next) where prev = M.elems $ foldl' (\acc [a,b] -> swap a b acc) start ab1s next = M.elems $ foldl' (\acc [a,b] -> swap a b acc) goal (reverse ab2s)