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 <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <math.h>

#define mp                  make_pair
#define F                   first
#define S                   second
#define pb                  push_back
#define FOR(i,j,n)          for(int i=j;i<n;i++)
#define F0R(i,j,n)          for(int i=j;i<=n;i++)
#define RFOR(i,j,n)         for(int i=n-1;i>=j;i--)
#define RF0R(i,j,n)         for(int i=n;i>=j;i--)
#define FOREACH(x,v)        for(auto x:v)
#define ITFOR(it,v)         for(v::iterator it =v.begin();it!=v.end();++it)
#define __in_arr__(a,j,n)   FOR(i,j,n)cin >> a[i];
#define __out_arr__(a,j,n)  FOR(i,j,n)cout << a[i];
#define LOG                 cout << "[ !" << __LINE__ << "L ] " << endl;
#define PLOG(x)             cout << "[ !" << __LINE__ << "L ] " \<<x<<endl;

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;

const int MAXN = 210;
const int INF = 5e9+10;
vii g[MAXN];
int dis[MAXN][MAXN];
int ro[MAXN];
int tmp[MAXN];


int brute_force(int x,bool*mark,int n,int ans,int prev) {
    if(x> n) return ans;
    int a = INF;
    FOR(i,0,n) {
        if(mark[i]) continue;
        mark[i] = true;
        a = min(a,brute_force(x+1,mark,n,ans+dis[ro[i]][prev],ro[i]));
        mark[i] = false;
    }
    return a;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n,m,r;
    cin >> n >> m >> r;
    FOR(i,0,r)
        cin >> ro[i];
    FOR(i,0,m) {
        int x,y,z;
        cin >> x >> y >> z;
        g[x].pb(mp(y,z));
        g[y].pb(mp(x,z));
    }
    F0R(i,1,n) { 
        fill(tmp,tmp+n,INF);
        tmp[i] = 0;
        for(auto u : g[i])
            tmp[u.F] = u.S;
        FOR(j,0,n) {
            int mn = INF,pos = 0;
            F0R(k,1,n)
                if(tmp[k] && tmp[k] < mn)
                    mn = tmp[k],pos = k;
            if(!pos)break;
            dis[i][pos] = tmp[pos];
            tmp[pos] = 0;
            for(auto w : g[pos])
                tmp[w.F] = min(tmp[w.F],w.S+dis[i][pos]);
        }
    }
    bool mark[8];
    fill(mark,mark+8,false);
    cout << brute_force(1,&mark[0],r,0,0) << endl;
    return 0;
}