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 C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
using namespace std;

//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  fspcnt = 0;
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int64_t n,m,r;
  cin >> n >> m >> r;
  //cout << n << "," << m << "," << r << endl;
  vector<int64_t> R(r);
  vector<int64_t> a(m),b(m),c(m);
  rep(i,r){
    cin >> R.at(i);
  }
  rep(i,m){
    cin >> a.at(i) >> b.at(i) >> c.at(i);
    //cout << c.at(i) << ",";
  }
  sort(R.begin(),R.end());
  vector<vector<int64_t>> distancex(n,vector<int64_t>(n));
  rep(i,n){
    rep(j,n){
      if(i == j){
        distancex.at(i).at(j) = 0;
      }else{
        distancex.at(i).at(j) = 10000000000000;
      }
    }
  }
  
  rep(i,m){
    distancex.at(a.at(i)-1).at(b.at(i)-1) = c.at(i);
    distancex.at(b.at(i)-1).at(a.at(i)-1) = c.at(i);
  }
  
  rep(i,n){
    rep(j,n){
      rep(k,n){
        if(distancex.at(i).at(j) > distancex.at(i).at(k) + distancex.at(k).at(j)){
          distancex.at(i).at(j) = distancex.at(i).at(k) + distancex.at(k).at(j);
          distancex.at(j).at(i) = distancex.at(i).at(k) + distancex.at(k).at(j);
        }
      }
    }
  }
  /*rep(i,n){
    rep(j,n){
      cout << distancex.at(i).at(j);
    }
    cout << endl;
  }*/
  int64_t shortest = 20000000000;
  do{
    int64_t distancetotal = 0;
    rep(i,r-1){
      distancetotal += distancex.at(R.at(i)-1).at(R.at(i+1)-1);
    }
    shortest = min(distancetotal,shortest);
  }while(next_permutation(R.begin(),R.end()));
  cout << shortest << endl;
      
      
    
  
  
}