import Control.Monad
import qualified Data.IntMap as M

type Table = M.IntMap Int

main :: IO ()
main = do
    [v,e,r] <- getInts
    es <- replicateM e $ do
        [s,t,d] <- getInts
        return (s,t,d)
    let vs = [0..v-1]
    putStrLn . unlines $ solve es r vs

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: [(Int,Int,Int)] -> Int -> [Int] -> [String]
solve es r vs = map (\v -> maybe "INF" show $ M.lookup v tbl) vs 
    where tbl = solve' es r

solve' :: [(Int,Int,Int)] -> Int -> Table
solve' es r = build (M.singleton r 0) [] [r]
    where
        build tbl xs [] = tbl
        build tbl xs (n:ns) = let vs = filter (\(s,_,_) -> n == s) es
                                  d = tbl M.! n
                                  xs' = n:xs
                                  tbl' = foldr (update d) tbl vs
                               in build tbl' xs' (ns ++ (filter (`notElem` xs') $ map (\(_,t,_) -> t) vs))

update :: Int -> (Int,Int,Int) -> Table -> Table
update d'' (s,t,d) tbl = M.insertWith min t (d+d'') tbl