#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
#define dbg(x) (cout<<#x<<" = "<<(x)<<'\n')
#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "team";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif
typedef long long int lld;
typedef pair<int, int> PII;
typedef pair<int, lld> PIL;
typedef pair<lld, int> PLI;
typedef pair<lld, lld> PLL;
const int INF = (1LL << 29) - 1;
const lld LINF = (1LL << 62) - 1;
const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
int N, M, P;
int DP[55][55][505];
bool viz[55][55][505];
int C[505][505];
int dest[55];
vector<PII> V[505];
priority_queue<PII, vector<PII>, greater<PII> > PQ;
void dijkstra(int x, int *D) {
int i, y, z;
bool viz[505];
for(i = 1; i <= N; i++) {
D[i] = INF;
viz[i] = 0;
}
D[x] = 0;
PQ.push(make_pair(0, x));
while(!PQ.empty()) {
x = PQ.top().second;
PQ.pop();
if(viz[x])
continue;
viz[x] = 1;
for(auto nod : V[x]) {
y = nod.first;
z = nod.second;
if(D[x] + z < D[y]) {
D[y] = D[x] + z;
PQ.push(make_pair(D[y], y));
}
}
}
}
int solve(int i, int j, int x) {
if(i > j)
return 0;
if(viz[i][j][x])
return DP[i][j][x];
int k, ans = INF;
for(k = i; k <= j; k++)
ans = min(ans, solve(i, k - 1, dest[k]) + solve(k + 1, j, dest[k]) + C[x][dest[k]]);
viz[i][j][x] = 1;
DP[i][j][x] = ans;
return DP[i][j][x];
}
int main() {
int i, j, k, x, y, z;
#ifndef ONLINE_JUDGE
freopen(inputFile.c_str(), "r", stdin);
freopen(outputFile.c_str(), "w", stdout);
#endif
scanf("%d%d%d", &P, &N, &M);
while(M--) {
scanf("%d%d%d", &x, &y, &z);
V[x].push_back(make_pair(y, z));
V[y].push_back(make_pair(x, z));
}
for(i = 1; i <= P; i++)
scanf("%d", &dest[i]);
for(i = 1; i <= N; i++)
dijkstra(i, C[i]);
printf("%d\n", solve(1, P, 1));
return 0;
}