import Data.List
import Data.Array.IO
import Data.IORef
import Control.Monad
import Control.Applicative

rInt = read :: String -> Int

type Ary = IOUArray (Int, Int) Int
type Var = IORef Int

infinity = 9999999

putAry ary s t d = do
    writeArray ary (s, t) d

putDAry ary [a, b, c] = do
    writeArray ary (a, b) c
    writeArray ary (b, a) c

getAry ary s t = do
    readArray ary (s, t)

updateAry ary s t k = do
    v <- readArray ary (s, t)
    k1 <- readArray ary (s, k)
    k2 <- readArray ary (k, t)
    writeArray ary (s, t) (min v (k1 + k2))

accum ary tmp (s, t) = do
    v <- getAry ary s t
    modifyIORef tmp (+v)

calc ary res path = do
    tmp <- newIORef 0
    mapM_ (accum ary tmp) (zip path (tail path))
    tvar <- readIORef tmp
    modifyIORef res (min tvar)



main = do
    [n, m, r] <- ((map rInt) . words) <$> getLine
    rs <- ((map rInt) . words) <$> getLine
    l <- map ((map rInt) . words) <$> replicateM m getLine
    array <- newArray ((1, 1), (n, n)) infinity :: IO Ary
    mapM_ (putDAry $ array) l
    mapM_ (\(k, i, j) -> updateAry array i j k) [(k, i, j) | k <- [1..n], i <- [1..n], j <- [1..n]]
    result <- newIORef infinity
    mapM_ (calc array result) $ permutations rs
    readIORef result >>= print
    --return ()