import Control.Monad type YukiCity = ([City],[Road]) cities = fst roads = snd 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 main = do [n,m,k] <- map read . words <$> getLine abcs <- map (map read . words) <$> replicateM m getLine let rs = map (\[a,b,c] -> ((a,b),c)) abcs info <- map read . words <$> getLine let result = investigate ([1..n],rs) (reverse info) print (length result) putStrLn (unwords (map show result)) investigate :: YukiCity -> Info -> [City] investigate yc i = filter (suspicion (roads yc) i) (cities yc) suspicion :: [Road] -> Info -> City -> Bool suspicion rs i = not . null . filter ((== length i) . length) . routeFrom rs i routeFrom :: [Road] -> Info -> City -> [[City]] routeFrom _ [] _ = [[]] routeFrom rs (i':i) c = do r <- rs guard (link c (path r)) guard (toll r == i') let c' = from c (path r) cs' <- routeFrom rs i c' return (c':cs')