Problem:
Score : 400 points

Problem Statement

There are N towns in the State of Atcoder, connected by M bidirectional roads.

The i-th road connects Town A_i and B_i and has a length of C_i.

Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order).

She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road.

If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?

Constraints

2≤N≤200

1≤M≤N×(N-1)/2

2≤R≤min(8,N) (min(8,N) is the smaller of 8 and N.)

r_i≠r_j (i≠j)

1≤A_i,B_i≤N, A_i≠B_i

(A_i,B_i)≠(A_j,B_j),(A_i,B_i)≠(B_j,A_j) (i≠j)

1≤C_i≤100000

Every town can be reached from every town by road.

All input values are integers.

Input

Input is given from Standard Input in the following format:

N M R
r_1 ... r_R
A_1 B_1 C_1
:
A_M B_M C_M

Output

Print the distance traveled by road if Joisino visits the towns in the order that minimizes it.

Sample Input 1

3 3 3
1 2 3
1 2 1
2 3 1
3 1 4

Sample Output 1

2

For example, if she visits the towns in the order of 1, 2, 3, the distance traveled will be 2, which is the minimum possible.

Sample Input 2

3 3 2
1 3
2 3 2
1 3 6
1 2 2

Sample Output 2

4

The shortest distance between Towns 1 and 3 is 4. Thus, whether she visits Town 1 or 3 first, the distance traveled will be 4.

Sample Input 3

4 6 3
2 3 4
1 2 4
2 3 3
4 3 1
1 4 1
4 2 2
3 1 6

Sample Output 3

3

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}


use std::cmp;
use std::collections::HashMap;




pub struct CALCDFS{
    visit : Vec<i32>,
    used : Vec<bool>,
    dp : Vec<Vec<i64>>,
    perm : Vec<usize>,
    ans : i64,
}

impl CALCDFS{
    pub fn new (n:usize ,m:usize,r:usize)-> Self{
        let max = 100000_i64 * 220_i64;
        CALCDFS{
            visit : vec![0;r],
            used : vec![false;9],
            dp :  vec![vec![max;n];n],
            perm : vec![0;r],
            ans : max
        }
    }

    pub fn dfs (&mut self , count : i32 ){
        if(count == (self.visit.len() as i32) ){
            let mut sum =0_i64;
            for i in 0..self.perm.len()-1{
                let a = self.visit[self.perm[i]] as usize;
                let b = self.visit[self.perm[i+1]] as usize;
                sum += self.dp[a][b];
            }
            self.ans = cmp::min(self.ans, sum );
            return;
        }
       
        for i in 0..self.visit.len(){
            if(self.used[i]){
                continue;
            }
            self.used[i] = true;
            self.perm[count as usize] = i;
            self.dfs( count+1);
            self.used[i] = false;
        }

    }
}




fn main() {

    input! { 
       n: usize,
       m: usize,
       r : usize,
       visit : [i32;r],
       a : [(usize,usize,i64);m]
    }


    let mut dfs = CALCDFS::new(n,m,r);
    for i in 0..r{
        dfs.visit[i] = visit[i]-1;
    }

    

    for i in 0..m{
        let (a,b,c) = a[i];
        dfs.dp[a-1][b-1] = c;
        dfs.dp[b-1][a-1] = c;
        //dp[i][i] = 0;
    }

    //dfs.dp[0][0] = 0;
    for k in 0..n{
        for i in 0..n{
            for j in 0..n{
                dfs.dp[i][j] = cmp::min(
                    dfs.dp[i][j],
                    dfs.dp[i][k] + dfs.dp[k][j]                    
                )
            }
        }
    }



    
    dfs.dfs(0);


    
    println!("{}",dfs.ans);


}