香甜的黄油
#include<iostream>
#include<cstring>
#include<cmath>
#define M 0x3f3f3f3f
using namespace std;
const int N=805;
int mapp[N][N],P[N];
int main(){
int n,p,c;
cin>>n>>p>>c;
int x,y,z;
while(n--){
scanf("%d",&x);
P[x]++;
}
memset(mapp,M,sizeof(mapp));
for(int i=0;i<c;i++){
scanf("%d%d%d",&x,&y,&z);
mapp[x][y]=mapp[y][x]=z;
}
//Floyd
for(int k=1;k<=p;k++)
for(int i=1;i<=p;i++)
for(int j=1;j<=p;j++)
mapp[i][j]=min(mapp[i][j],mapp[i][k]+mapp[k][j]);
//枚举每一个点
int ans=0x7fffffff;
for(int i=1;i<=p;i++){
int sum=0;
for(int j=1;j<=p;j++){
if(i==j)continue;
sum+=mapp[j][i]*P[j];
}
ans=min(ans,sum);
}
cout<<ans;
return 0;
}