#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap};
use std::iter::FromIterator;
fn main() {
    input! {
        N: usize,
        M: usize,
        R: usize,
        r: [usize1; R],
        roads: [(usize1, usize1, usize); M],
    }

    let mut costs = vec![vec![10_000_000; N]; N];
    for &(a, b, cost) in roads.iter() {
        costs[a][b] = cost;
        costs[b][a] = cost;
    }

    for (ind, &r1) in r.iter().enumerate() {
        for &r2 in r.iter().skip(ind+1) {
            let mut d = [std::usize::MAX; 200];
            let mut q: HashSet<usize> = HashSet::from_iter(0..N);
            d[r1] = 0;

            while let Some(&prev) = q.iter().min_by_key(|&&i| d[i]) {
                if prev == r2 { break; }
                q.remove(&prev);

                for &q in q.iter() {
                    d[q] = cmp::min(d[q], d[prev] + costs[prev][q]);
                }
            }
            costs[r1][r2] = d[r2];
            costs[r2][r1] = d[r2];
        }
    }

    let mut ans = std::usize::MAX;

    'outer: for perm in 0..(R.pow(R as u32)) {
        let mut rest = perm;
        let mut c = [0; 8];
        let mut used = [false; 8];
        for ind in 0..R {
            c[ind] = rest % R;
            if used[c[ind]] {
                continue 'outer;
            } else {
                used[c[ind]] = true;
            }
            rest /= R;
        }

        let mut sum = 0;
        for ind in 0..R-1 {
            sum += costs[r[c[ind]]][r[c[ind+1]]];
        }
        ans = cmp::min(ans, sum);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352