Language: C++

import Data.Array.Unboxed ((!))
import qualified Data.Array.Unboxed as A
import qualified Data.Array.ST      as S
import qualified Control.Monad      as C

-- サンプル内でのみ利用
import Data.List
import Control.Applicative

type Table = A.Array Int
type Graph = Table [Edge]
data Edge  = Edge 
    { toEdge   :: Int
    , costEdge :: Int
    } deriving (Show, Eq, Ord)

inf :: Int
inf = 10000000000

bellmanFord :: Int              -- 絶対地点
            -> Graph 
            -> A.UArray Int Int -- 絶対地点からの最短距離
bellmanFord s graph = S.runSTUArray $ do
    let (bs,be) = A.bounds graph
    shortestPath <- S.newArray (bs,be) inf
    S.writeArray shortestPath s 0

    C.forM_ [bs..be] $ \_ ->
        C.forM_ [(f, toEdge e, costEdge e)|f<-[bs..be], e<-graph!f] $ \(from, to, edgeCost) -> do
            fromCost <- S.readArray shortestPath from
            toCost   <- S.readArray shortestPath to

            -- 直前まで意味のある値が求まっている && より良い辺を見つけた
            C.when (fromCost /= inf && toCost > fromCost+edgeCost)
                $ S.writeArray shortestPath to $ fromCost + edgeCost

    return shortestPath            

groupFstElems :: Eq a => [(a, b)] -> [(a, [b])]
groupFstElems = flip groupFstElems' []
    where
    groupFstElems' :: Eq a => [(a, b)] -> [(a, [b])] -> [(a, [b])]
    groupFstElems' [] ys         = ys
    groupFstElems' (x:xs) []     = groupFstElems' xs [(fst x, [snd x])]
    groupFstElems' (x:xs) (y:ys) = if fst x == fst y 
        then groupFstElems' xs ((fst y, snd x:snd y):ys)
        else groupFstElems' xs ((fst x, [snd x]):y:ys)

main :: IO ()
main = do
    [v,e,r] <- map read . words <$> getLine :: IO [Int]

    edges <- groupFstElems . sort <$> C.replicateM e (
        (\[s,t,d]->(s,Edge t d)) . map read . words <$> getLine :: IO (Int, Edge)) :: IO [(Int, [Edge])]

    let nullEdges = [(i, [])|i<-[0..v-1]]
        graph = A.array (0,v-1) (nullEdges ++ edges) :: Graph

    let shortestPath = bellmanFord r graph :: A.UArray Int Int

    C.forM_ [0..v-1] $ \i ->
        putStrLn $ if shortestPath ! i == inf then "INF" else show $ shortestPath ! i



Compiler output:
a.cc:28:24: error: stray '\' in program
   28 |     C.forM_ [bs..be] $ \_ ->
      |                        ^
a.cc:29:71: error: stray '\' in program
   29 |         C.forM_ [(f, toEdge e, costEdge e)|f<-[bs..be], e<-graph!f] $ \(from, to, edgeCost) -> do
      |                                                                       ^
a.cc:40:35: warning: missing terminating ' character
   40 | groupFstElems = flip groupFstElems' []
      |                                   ^
a.cc:40:35: error: missing terminating ' character
   40 | groupFstElems = flip groupFstElems' []
      |                                   ^~~~
a.cc:42:18: warning: missing terminating ' character
   42 |     groupFstElems' :: Eq a => [(a, b)] -> [(a, [b])] -> [(a, [b])]
      |                  ^
a.cc:42:18: error: missing terminating ' character
   42 |     groupFstElems' :: Eq a => [(a, b)] -> [(a, [b])] -> [(a, [b])]
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:43:18: warning: missing terminating ' character
   43 |     groupFstElems' [] ys         = ys
      |                  ^
a.cc:43:18: error: missing terminating ' character
   43 |     groupFstElems' [] ys         = ys
      |                  ^~~~~~~~~~~~~~~~~~~~
a.cc:44:18: warning: multi-character literal with 30 characters exceeds 'int' size of 4 bytes
   44 |     groupFstElems' (x:xs) []     = groupFstElems' xs [(fst x, [snd x])]
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:45:18: warning: missing terminating ' character
   45 |     groupFstElems' (x:xs) (y:ys) = if fst x == fst y
      |                  ^
a.cc:45:18: error: missing terminating ' character
   45 |     groupFstElems' (x:xs) (y:ys) = if fst x == fst y
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
a.cc:46:27: warning: missing terminating ' character
   46 |         then groupFstElems' xs ((fst y, snd x:snd y):ys)
      |                           ^
a.cc:46:27: error: missing terminating ' character
   46 |         then groupFstElems' xs ((fst y, snd x:snd y):ys)
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:47:27: warning: missing terminating ' character
   47 |         else groupFstElems' xs ((fst x, [snd x]):y:ys)
      |                           ^
a.cc:47:27: error: missing terminating ' character
   47 |         else groupFstElems' xs ((fst x, [snd x]):y:ys)
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:54:10: error: stray '\' in program
   54 |         (\[s,t,d]->(s,Edge t d)) . map read . words <$> getLine :: IO (Int, Edge)) :: IO [(Int, [Edge])]
      |          ^
a.cc:56:34: error: too many decimal points in number
   56 |     let nullEdges = [(i, [])|i<-[0..v-1]]
      |                                  ^~~~
a.cc:61:14: error: too many decimal points in number
   61 |     C.forM_ [0..v-1] $ \i ->
      |              ^~~~
a.cc:61:24: error: stray '\' in program
   61 |     C.forM_ [0..v-1] $ \i ->
      |                        ^
a.cc:1:1: error: 'import' does not name a type
    1 | import Data.Array.Unboxed ((!))
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:15:16: error: expected constructor, destructor, or type conversion before '(' token
   15 |     } deriving (Show, Eq, Ord)
      |                ^