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:39:35: warning: missing terminating ' character
   39 | groupFstElems = flip groupFstElems' []
      |                                   ^
a.cc:39:35: error: missing terminating ' character
   39 | groupFstElems = flip groupFstElems' []
      |                                   ^~~~
a.cc:41:18: warning: missing terminating ' character
   41 |     groupFstElems' :: Eq a => [(a, b)] -> [(a, [b])] -> [(a, [b])]
      |                  ^
a.cc:41:18: error: missing terminating ' character
   41 |     groupFstElems' :: Eq a => [(a, b)] -> [(a, [b])] -> [(a, [b])]
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:42:18: warning: missing terminating ' character
   42 |     groupFstElems' [] ys         = ys
      |                  ^
a.cc:42:18: error: missing terminating ' character
   42 |     groupFstElems' [] ys         = ys
      |                  ^~~~~~~~~~~~~~~~~~~~
a.cc:43:18: warning: multi-character literal with 30 characters exceeds 'int' size of 4 bytes
   43 |     groupFstElems' (x:xs) []     = groupFstElems' xs [(fst x, [snd x])]
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:44:18: warning: missing terminating ' character
   44 |     groupFstElems' (x:xs) (y:ys) = if fst x == fst y
      |                  ^
a.cc:44:18: error: missing terminating ' character
   44 |     groupFstElems' (x:xs) (y:ys) = if fst x == fst y
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
a.cc:45:27: warning: missing terminating ' character
   45 |         then groupFstElems' xs ((fst y, snd x:snd y):ys)
      |                           ^
a.cc:45:27: error: missing terminating ' character
   45 |         then groupFstElems' xs ((fst y, snd x:snd y):ys)
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:46:27: warning: missing terminating ' character
   46 |         else groupFstElems' xs ((fst x, [snd x]):y:ys)
      |                           ^
a.cc:46:27: error: missing terminating ' character
   46 |         else groupFstElems' xs ((fst x, [snd x]):y:ys)
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:53:10: error: stray '\' in program
   53 |         (\[s,t,d]->(s,Edge t d)) . map read . words <$> getLine :: IO (Int, Edge)) :: IO [(Int, [Edge])]
      |          ^
a.cc:55:34: error: too many decimal points in number
   55 |     let nullEdges = [(i, [])|i<-[0..v-1]]
      |                                  ^~~~
a.cc:60:14: error: too many decimal points in number
   60 |     C.forM_ [0..v-1] $ \i ->
      |              ^~~~
a.cc:60:24: error: stray '\' in program
   60 |     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)
      |                ^