(ns Atcoder.ABC073-D)

(def INF 10000000000)
(defn G_init [V] (vec (for [ _ (range 0 V)] [])))
(defn G_init_with_Val [V Val idx] (vec (for [ _ (range 0 V)] (if (= idx _) 0 Val))))

(def input (vec (map read-string (clojure.string/split (read-line) #" "))))
(def N (nth input 0)) (def M (nth input 1)) (def R (nth input 2))
(def r (vec (map read-string (clojure.string/split (read-line) #" "))))
(def abc (loop [input [] i 0]
           (if (= i M)
             input
             (recur (conj input (vec (map read-string (clojure.string/split (read-line) #" ")))) (inc i)))))

;(println N M R r abc)
(def G (G_init N))
(def initdist (loop [G G i 0]
             (if (= i N)
               G
               (recur (assoc G i (G_init_with_Val N INF i)) (inc i)))))

(def dist (loop [dist initdist i 0]
                  (if (= i M)
                    dist
                    (let [u (dec (nth (nth abc i) 0)) v (dec (nth (nth abc i) 1)) w (nth (nth abc i) 2)]
                      (let [tmp (assoc dist u (assoc (nth dist u) v w))]
                        (recur (assoc tmp v (assoc (nth tmp v) u w)) (inc i)))))))
;(println dist)

(doseq [x (range N)
        y (range N)
        z (range N)]
  (def dist (assoc dist y (assoc (nth dist y) z (min (nth (nth dist y) z) (+ (nth (nth dist y) x) (nth (nth dist x) z))))))
  )

;(println dist)

;(println r)
;(println (range 1 R))
(def ans (for [i (range 1 R)]
           (nth (nth dist (dec (nth r (dec i)))) (dec (nth r i)))))

(println (reduce + 0 ans))