module Main where
import Data.List(permutations)
import Data.Array

int = read :: String -> Int

main = interact $ printer . solver . parser

wf :: Int -> Array (Int,Int) Int -> Array (Int,Int) Int 
wf n a = result
  where    
    nm = n - 1
    wf' :: Int -> Array (Int,Int) Int -> Array (Int,Int) Int 
    wf' k a = array ((0,0),(nm,nm)) [((i,j),min (a!(i,j)) ((a!(i,k))+(a!(k,j)))) | i<-[0..nm],j<-[0..nm]] 
    funcs = map wf' [0..nm] :: [Array (Int,Int) Int -> Array (Int,Int) Int]
    result = foldl (flip id) a funcs

printer :: Int -> String
printer = unlines . (:[]) . show 

parser :: String -> (Int, [Int], Array (Int,Int) Int)
parser input = (n, rms, arr)
  where
    (n:m:r:is1) = map int . words $ input
    (rs,is2) = splitAt r is1
    rms = map (subtract 1) rs
    abcs = map (take 3) $ take m $ iterate (drop 3) is2
    nm = n-1
    arr = array ((0,0),(nm,nm)) ([((i,j),200000) |i<-[0..nm],j<-[0..nm] ] ++ (concat $ map (\[a,b,c]->[((a-1,b-1),c),((b-1,a-1),c)]) abcs))

distance :: Array (Int,Int) Int -> [Int] -> Int
distance arr rs = sum $ zipWith (\x y -> arr ! (x,y)) rs (tail rs)

solver :: (Int, [Int], Array (Int,Int) Int) -> Int
solver (n, rs, arr) = result 
  where
    arr2 = wf n arr
    result = minimum $ map (distance arr2) $ permutations rs
