https://ac.nowcoder.com/acm/contest/5670/A
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=350;
ll n,m,k,d[maxn][maxn],a[maxn*2],f[maxn*2][maxn];
int main()
{
//freopen("input.in","r",stdin);
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
d[i][j]=(1LL<<50);
for(int i=1;i<=n;i++)d[i][i]=0;
ll u,v,w;
while(m--)
{
cin>>u>>v>>w;
d[u][v]=d[v][u]=min(d[u][v],w);
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
for(int i=1;i<=2*k;i++)cin>>a[i];
a[0]=1;
for(int i=0;i<=2*k;i++)for(int j=1;j<=n;j++)f[i][j]=(1LL<<50);
f[0][1]=0;
for(int i=0;i<2*k;i++)
{
for(int p=1;p<=n;p++)
{
f[i+1][p]=min(f[i+1][p],f[i][p]+d[a[i]][a[i+1]]);
for(int q=1;q<=n;q++)
{
f[i+1][q]=min(f[i+1][q],f[i][p]+d[a[i]][q]+d[p][a[i+1]]);
f[i+1][q]=min(f[i+1][q],f[i][p]+d[p][q]+d[q][a[i+1]]);
}
}
}
ll ans=(1LL<<50);
for(int i=1;i<=n;i++)ans=min(ans,f[2*k][i]);
cout<<ans<<endl;
return 0;
}