Cod sursa(job #659177)
#include <cstdio>
#include <cstring>
const int INF = int(2e9);
int N , M , K , C[16] , D[2002][2002] , ans = INF;
int sol[16] , use[16] , cost;
static inline int min(int a,int b) { return a < b ? a : b;}
void back(int k)
{
if(k == K + 1)
ans = min(ans,cost + D[C[sol[K]]][N]);
else
for(int i = 1;i<=K;++i)
if(use[i] == 0)
{
int c = D[C[sol[k-1]]][C[i]];
use[i] = 1;
sol[k] = i;
cost = cost + c;
back(k+1);
cost = cost - c;
use[i] = 0;
}
}
void roy_floyd()
{
for(int k = 1;k<=N;++k)
for(int i = 1;i<=N;++i)
if(k!=i)
for(int j = 1;j<=N;++j)
if(i!=j && D[i][k] && D[k][j] && (!D[i][j] || D[i][k] + D[k][j] < D[i][j]))
D[i][j] = D[i][k] + D[k][j];
}
void read_data()
{
freopen("ubuntzei.in","r",stdin);
freopen("ubuntzei.out","w",stdout);
scanf("%d %d %d",&N,&M,&K);
for(int i = 1;i<=K;++i)
scanf("%d",&C[i]);
C[0] = 1;
int a , b ,c;
for(;M;M--)
{
scanf("%d %d %d",&a,&b,&c);
D[a][b] = D[b][a] = c;
}
}
int main()
{
read_data();
roy_floyd();
if(K == 0) ans = D[1][N];
else
back(1);
printf("%d\n",ans);
return 0;
}