import Control.Monad import Data.List import qualified Data.Set as S type YukiCity = ([City],[Road]) cities = fst roads = snd next rs c t = map (from c . fst) $ filter (\r -> link c (path r) && toll r == t) rs type Road = (Path,Toll) path = fst toll = snd type Path = (City,City) link c (c1,c2) = c==c1 || c==c2 from c (c1,c2) | c == c1 = c2 | c == c2 = c1 type Info = [Toll] type City = Int type Toll = Int nub' = S.toList . S.fromList main = do [n,m,k] <- map read . words <$> getLine abcs <- map (map read . words) <$> replicateM m getLine info <- map read . words <$> getLine let rs = map (\[a,b,c] -> ((a,b),c)) abcs let result = investigate ([1..n],rs) info print (length result) putStrLn (unwords (map show result)) investigate :: YukiCity -> Info -> [City] investigate yc i = foldl' (move (roads yc)) (cities yc) i move :: [Road] -> [City] -> Toll -> [City] move rs cs t = nub' $ concatMap (\c -> next rs c t) cs