output_description: Print the distance traveled by road if Joisino visits the towns in the order
  that minimizes it.
  
  * * *
input_description: 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
attempt: import java.util.*;
  public class Main {
  	
  	static boolean[] used;
  	static int[] r;
  	static int[][] d;
  	static int INF = Integer.MAX_VALUE/2, R;
  	static long ans = INF;
  	
  	static void dfs(int now, long cost, int cnt) {
  		if(cnt == R) {
  			ans = Math.min(ans, cost);
  			return;
  		}
  		for(int i : r)
  			if(!used[i]) {
  				used[i] = true;
  				dfs(i, cost + d[now][i], cnt + 1);
  				used[i] = false;
  			}
  	}
  	
  	public static void main(String[] args) {
  		Scanner sc = new Scanner(System.in);
  		int N = sc.nextInt();
  		int M = sc.nextInt();
  		R = sc.nextInt();
  		r = new int[R];
  		used = new boolean[N];
  		d = new int[N][N];
  		Arrays.setAll(r, i -> sc.nextInt()-1);
  		for(int i = 0; i < N; i++)
  			for(int j = 0; j < N; j++)
  				if(i != j)
  					d[i][j] = INF;
  		for(int i = 0; i < M; i++) {
  			int A = sc.nextInt()-1;
  			int B = sc.nextInt()-1;
  			int C = sc.nextInt();
  			d[A][B] = C;
  			d[B][A] = C;
  		}
  		for(int k = 0; k < N; k++)
  			for(int i = 0; i < N; i++)
  				for(int j = 0; j < N; j++)
  					d[i][j] = Math.min(d[i][j], d[i][k] + d[j][k]);
  		for(int i : r) {
  			used[i] = true;
  			dfs(i, 0, 1);
  			used[i] = false;
  		}
  		System.out.println(ans);
  	}
  
  }
problem_description: 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?
samples: [{"input": "3 3 3\n    1 2 3\n    1 2 1\n    2 3 1\n    3 1 4", "output": "2\n    \n\nFor example, if she visits the towns in the order of 1, 2, 3, the distance\ntraveled will be 2, which is the minimum possible.\n\n* * *"}, {"input": "3 3 2\n    1 3\n    2 3 2\n    1 3 6\n    1 2 2", "output": "4\n    \n\nThe shortest distance between Towns 1 and 3 is 4. Thus, whether she visits\nTown 1 or 3 first, the distance traveled will be 4.\n\n* * *"}, {"input": "4 6 3\n    2 3 4\n    1 2 4\n    2 3 3\n    4 3 1\n    1 4 1\n    4 2 2\n    3 1 6", "output": "3"}]