#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define INF 0x7ffffff
using namespace std;
struct EdgeType {
int to,dis,next;
};
struct EdgeType edge[3005];
int n,p,m,bel[805],cnt,ans=INF;
int head[805],dis[805],que[3005];
bool if_[805];
char Cget;
inline void in(int &now)
{
now=0,Cget=getchar();
while(Cget>‘9‘||Cget<‘0‘) Cget=getchar();
while(Cget>=‘0‘&&Cget<=‘9‘)
{
now=now*10+Cget-‘0‘;
Cget=getchar();
}
}
int main()
{
in(n),in(p),in(m);int u,v,w;
for(int i=1;i<=n;i++) in(bel[i]);
for(int i=1;i<=m;i++)
{
in(u),in(v),in(w);
edge[++cnt].to=v,edge[cnt].next=head[u],edge[cnt].dis=w,head[u]=cnt;
edge[++cnt].to=u,edge[cnt].next=head[v],edge[cnt].dis=w,head[v]=cnt;
}
for(int s=1;s<=p;s++)
{
for(int i=1;i<=p;i++) dis[i]=INF;
int he=0,ta=0;if_[s]=true,dis[s]=0;
que[ta++]=s;
while(he<ta)
{
int pos=que[he];he++;
for(int i=head[pos];i;i=edge[i].next)
{
if(dis[edge[i].to]>dis[pos]+edge[i].dis)
{
dis[edge[i].to]=dis[pos]+edge[i].dis;
if(!if_[edge[i].to])
{
if_[edge[i].to]=true;
que[ta++]=edge[i].to;
}
}
}
if_[pos]=false;
}
int tot=0;
for(int i=1;i<=n;i++) tot+=dis[bel[i]];
if(tot<ans) ans=tot;
}
cout<<ans;
return 0;
}