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: Accepted)

// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
//const ll INF = 10000000000;//INFinity
const int INF = 1000000000;
using namespace std;//namespace

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}//transform
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//#define int long long // yabai

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout

#define FOR(i,a,b) for(int i=(a);i<(b);++i)// for macro
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    int n,m,r;
    cin>>n>>m>>r;
    vector<int> visit(r);
    struct road{
        int a,b,c;
    };
    vector<road> roads(m);
    REP(i,r)cin>>visit[i];
    REP(i,m)cin>>roads[i].a>>roads[i].b>>roads[i].c;

    vector<vector<int>> sides(n+1);
    for(auto&s:sides){s.resize(n+1);for(auto&m:s)m=INF;}
    REP(i,n+1)sides[i][i]=0;
    for(auto ro:roads){
        sides[ro.a][ro.b]=ro.c;sides[ro.b][ro.a]=ro.c;
    }
    REP(k,n+1)REP(i,n+1)REP(j,n+1)sides[i][j]=min(sides[i][j],sides[i][k]+sides[k][j]);
    /*
    map<int,vector<pair<int,int>>> map_;
    for(auto x:visit)for(auto y:visit)map_[x].push_back(mp(y,sides[x][y]));
    for(auto rrr:visit)for(auto rr:map_[rrr])cout<<rrr<<" "<<rr.first<<" "<<rr.second<<endl;
    */
    map<pair<int,int>,int> map_;
    for(auto x:visit)for(auto y:visit)map_[mp(x,y)]=sides[x][y];

    vector<int> suii(r,0); 
    int min_=INF;
    while(count(suii.begin(),suii.end(),r-1)!=r){
        REP(i,r){
            if(suii[i]==r-1){suii[i]=0;continue;}
            if(suii[i]!=r-1){
                suii[i]++;
                int sum=0;
                bool flag=true;
                REP(i,r-1)if(count(suii.begin(),suii.end(),i)!=1){flag=false;break;}
                if(flag){
                    REP(i,r-1)sum+=map_[mp(visit[suii[i]],visit[suii[i+1]])];
                    min_=min(min_,sum);
                }
                break;
            }
        }
    }
    cout<<min_<<endl;
    return 0;
}