1 #include<bits/stdc++.h>
2 using namespace std;
3 #define INF 1e9
4 struct node
5 {
6 int begin,end,value,next;
7 }edge[2910];
8 int cnt,Head[810],a[510],n,p,f[810],dis[810],Heap[810],pos[810],SIZE;
9 int read()
10 {
11 int s=0,fh=1;char ch=getchar();
12 while(ch<'0'||ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
13 while(ch>='0'&&ch<='9'){s=s*10+(ch-'0');ch=getchar();}
14 return s*fh;
15 }
16 void addedge(int bb,int ee,int vv)
17 {
18 edge[++cnt].begin=bb;edge[cnt].end=ee;edge[cnt].value=vv;edge[cnt].next=Head[bb];Head[bb]=cnt;
19 }
20 void addedge1(int bb,int ee,int vv)
21 {
22 addedge(bb,ee,vv);addedge(ee,bb,vv);
23 }
24 void Push1(int k)
25 {
26 int now=k,root;
27 while(now>1)
28 {
29 root=now/2;
30 if(dis[Heap[root]]<=dis[Heap[now]])return;
31 swap(Heap[root],Heap[now]);
32 swap(pos[Heap[root]],pos[Heap[now]]);
33 now=root;
34 }
35 }
36 void Insert(int k)
37 {
38 Heap[++SIZE]=k;pos[k]=SIZE;Push1(SIZE);
39 }
40 void Pop1(int k)
41 {
42 int now,root=k;
43 pos[Heap[k]]=0;Heap[k]=Heap[SIZE--];if(SIZE>0)pos[Heap[k]]=k;
44 while(root<=SIZE/2)
45 {
46 now=root*2;
47 if(now<SIZE&&dis[Heap[now+1]]<dis[Heap[now]])now++;
48 if(dis[Heap[root]]<=dis[Heap[now]])return;
49 swap(Heap[root],Heap[now]);
50 swap(pos[Heap[root]],pos[Heap[now]]);
51 root=now;
52 }
53 }
54 void dijkstra(int start)
55 {
56 int i,u,v;
57 for(i=1;i<=p;i++)dis[i]=INF;dis[start]=0;
58 for(i=1;i<=p;i++)Insert(i);
59 while(SIZE>0)
60 {
61 u=Heap[1];Pop1(pos[u]);
62 for(i=Head[u];i!=-1;i=edge[i].next)
63 {
64 v=edge[i].end;
65 if(dis[v]>dis[u]+edge[i].value){dis[v]=dis[u]+edge[i].value;Push1(pos[v]);}
66 }
67 }
68 }
69 int main()
70 {
71 freopen("butter.in","r",stdin);
72 freopen("butter.out","w",stdout);
73 int c,s1,s2,s3,i,j,MN;
74 n=read();p=read();c=read();
75 for(i=1;i<=n;i++)a[i]=read();
76 memset(Head,-1,sizeof(Head));cnt=1;
77 SIZE=0;
78 for(i=1;i<=c;i++)
79 {
80 s1=read();s2=read();s3=read();
81 addedge1(s1,s2,s3);
82 }
83 memset(f,0,sizeof(f));
84 for(i=1;i<=n;i++)
85 {
86 dijkstra(a[i]);
87 for(j=1;j<=p;j++)f[j]+=dis[j];
88 }
89 MN=INF;
90 for(i=1;i<=p;i++)MN=min(MN,f[i]);
91 printf("%d",MN);
92 fclose(stdin);
93 fclose(stdout);
94 return 0;
95 }