{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad         (forM_, when)
import qualified Data.Array.MArray     as MA
import           Data.Array.ST         (runSTUArray)
import           Data.Array.Unboxed    (UArray, (!))
import qualified Data.ByteString.Char8 as BS
import           Data.List             (permutations)
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  [n, m, r] <- readInts <$> BS.getLine
  rs <- readInts <$> BS.getLine
  abcs <- map readInts . BS.lines <$> BS.getContents
  print $ solve n m r rs abcs

solve :: Int -> Int -> Int -> [Int] -> [[Int]] -> Int
solve n m _ rs abcs = minimum . map travel $ permutations rs where
  travel ss = sum . map (dss !) . zip ss $ tail ss
  dss = warshallFloyd n m abcs

warshallFloyd :: Int -> Int -> [[Int]] -> UArray (Int, Int) Int
warshallFloyd n _ abcs = runSTUArray $ do
  dss <- MA.newArray ((1, 1), (n, n)) (maxBound `div` 3)
  forM_ abcs $ \[a, b, c] -> do
    MA.writeArray dss (a, b) c
    MA.writeArray dss (b, a) c
  forM_ [1 .. n] $ \k ->
    forM_ [1 .. n] $ \i ->
      forM_ [1 .. n] $ \j -> do
        dij <- MA.readArray dss (i, j)
        dik <- MA.readArray dss (i, k)
        dkj <- MA.readArray dss (k, j)
        when (dij > dik + dkj) $
          MA.writeArray dss (i, j) (dik + dkj)
  return dss

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

readInts :: BS.ByteString -> [Int]
readInts = map readInt . BS.words
