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)

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;

using lint = long long;
const lint MOD = 1e9 + 7;
const int INF = 1e9;
const lint LINF = 1e18;
using flt = double;
const flt E = exp(1.0);
const flt PI = acos(-1.0);

// Class ModInteger<MOD>
template <lint mod>
class ModInteger {
    public:
    lint val;

    // Constructor
    ModInteger(): val(0) {}
    ModInteger(lint ival): val(ival >= 0? ival%mod: mod - (-ival)%mod) {}

    // Comparators
    bool operator !() {return val == 0;}
    bool operator <(ModInteger that) {return val < that.val;}
    bool operator >(ModInteger that) {return val > that.val;}
    bool operator <=(ModInteger that) {return val <= that.val;}
    bool operator >=(ModInteger that) {return val >= that.val;}
    bool operator ==(ModInteger that) {return val == that.val;}
    bool operator !=(ModInteger that) {return val != that.val;}

    // Basic operations
    ModInteger operator ++() {val++; return *this;}
    ModInteger operator --() {val--; return *this;}

    ModInteger& operator +=(ModInteger that) {val = (val + that.val)%mod; return *this;}
    ModInteger& operator -=(ModInteger that) {val = ((val - that.val)%mod + mod)%mod; return *this;}
    ModInteger& operator *=(ModInteger that) {val = (val*that.val)%mod; return *this;}
    ModInteger& operator /=(ModInteger that) {
        lint inv = that.val, rem = 1, power = mod - 2;
        while (power > 1) {if (power%2) rem = (rem*inv)%mod; inv = (inv*inv)%mod; power /= 2;}
        inv = (rem*inv)%mod;
        val = (val*inv)%mod;
        return *this;
    }

    ModInteger operator +(ModInteger that) {return ModInteger(*this) += that;}
    ModInteger operator -(ModInteger that) {return ModInteger(*this) -= that;}
    ModInteger operator *(ModInteger that) {return ModInteger(*this) *= that;}
    ModInteger operator /(ModInteger that) {return ModInteger(*this) /= that;}
    
    ModInteger& operator %=(ModInteger that) {val = val%that.val; return *this;}
    ModInteger operator %(ModInteger that) {return ModInteger(*this) %= that;}
}; using mint = ModInteger<MOD>;

// ModInteger input & output
istream& operator >>(istream& is, mint& n) {return is >> n.val;}
ostream& operator <<(ostream& os, mint n) {return os << n.val;}

// Macros
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define bit(n) (lint)1<<n
#define mrep(it, m) for (auto it = m.begin(); it != num.end(); it++)
#define fi first
#define se second
#define pint pair<int, int>
#define plint pair<lint, lint>
#define mp make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vlint vector<lint>
#define vvlint vector<vector<lint>>
#define pb push_back
#define all(v) v.begin(), v.end()
#define asort(v) sort(all(v))
#define dsort(v) sort(all(v)); reverse(all(v))
#define maxval(v) *max_element(all(v))
#define maxindex(v) distance(v.begin(), max_element(all(v)))
#define minval(v) *min_element(all(v))
#define minindex(v) distance(v.begin(), min_element(all(v)))

// Sort by an arbitrary comparator (example)
/*
    sort(all(v), [](pint a, pint b) {return !(a.se == b.se)? a.se < b.se: a.fi < b.fi;});
*/

// Basic functions (be careful of overflowing!)
template <typename Tp>
Tp gcd(Tp m, Tp n) {
    if (!m || !n) {cout << "GCD error: zero inputed" << endl; return 0;}
    else if (!(m%n)) return n;
    else return gcd(n, m%n);
}
template <typename Tp>
Tp lcm(Tp m, Tp n) {
    if (!m || !n) {cout << "LCM error: zero inputed" << endl; return 0;}
    else return m*n/gcd(m, n);
}
template <typename Tp1, typename Tp2>
Tp1 ipow(Tp1 a, Tp2 p) {// For integers
    if (p < 0) {cout << "Power error: a minus number inputed" << endl; return 0;}
    else if (!p) return 1;
    Tp1 res = a, rem = 1;
    while (p > 1) {if (p%2) rem *= res; res *= res; p /= 2;}
    return rem*res;
}
template <typename Tp>
Tp fact(Tp n) {// Facorial: requires O(n)
    if (n < 0) {cout << "Factorial error: a minus number inputed" << endl; return 0;}
    else if (!n) return 1;
    else if (n == 1) return 1;
    else return n*fact(n - 1);
}
template <typename Tp>
void pfact(Tp n, map<Tp, int>& res) {// Prime factorization: requires O(sqrt(n))
    if (n <= 1) {cout << "Prime factorization error: cannot factorize an integer less than 2" << endl; return;}
    if (res.size()) cout << "Prime factorization warning: the map already contains some numbers" << endl;
    Tp pos = 2, pmax = n;
    while (pos*pos <= pmax) {if (!(n%pos)) {res[pos]++; n /= pos;} else pos++;}
    if (n != 1) res[n]++;
    return;
}
template <typename Tp>
Tp comb(Tp n, Tp r) {// Requires O(r)
    if (n < 0 || r < 0) {cout << "Combination error: a minus number inputed" << endl; return 0;}
    else {lint res = 1; rep(i, r) res *= (n - i)/(i + 1); return res;}
}

// Format for cout
/*
    // Integers
    cout << 42; -> 42
    cout << setfill('0') << setw(6) << 42; -> 000042

    // Floats
    cout << PI; -> 3.14159
    cout << fixed << PI; -> 3.141593 
    cout << fixed << setprecision(8) << PI; -> 3.14159265
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M, R;
    cin >> N >> M >> R;

    vint r(R);
    rep(i, R) {cin >> r[i]; r[i]--;}

    vvint dist(N, vint(N, INF));
    rep(i, M) {
        int A, B, C; cin >> A >> B >> C; A--; B--;
        dist[A][B] = dist[B][A] = C;
    }

    // Warshall–Floyd
    rep(k, N) rep(i, N) rep(j, N) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    int ans = INF;
    sort(all(r));
    do {
        int cand = 0;
        rep(i, R - 1) cand += dist[r[i]][r[i + 1]];
        ans = min(ans, cand);
    } while (next_permutation(all(r)));

    cout << ans << endl;
    return 0;
}