#include<stdio.h>
#include<string.h>
#include<stdbool.h>
#define P 810
#define C 1460
int n, p, c;
int dist[P];
int st[P];
int h[P], cnt;
struct edge{
int to;
int next;
int weight;
}E[C*2];
void add(int v, int w, int weight){
E[++cnt].next = h[v];
E[cnt].to = w;
E[cnt].weight = weight;
h[v] = cnt;
}
int que[P];
bool inQue[P];
int head, tail;
int spfa(int x){
dist[x] = 0;
que[++tail] = x, inQue[x] = true;
while(head != tail){
int t = que[++head];
head %= P; //循环队列
inQue[t] = false;
for(int i = h[t]; i != -1; i = E[i].next){
int j = E[i].to;
if(dist[j] > dist[t] + E[i].weight){
dist[j] = dist[t] + E[i].weight;
if(!inQue[j]){
que[++tail] = j;
tail %= P;
inQue[j] = true;
}
}
}
}
int res = 0;
for(int j = 1; j <= p; j++)
if(st[j] > 0) res += st[j]*dist[j];
return res;
}
int main(){
scanf("%d %d %d", &n, &p, &c);
memset(h, -1, sizeof h);
for(int i = 1; i <= n; i++){
int x; scanf("%d", &x);
st[x]++;
}
for(int i = 1; i <= c; i++){
int a, b, w;
scanf("%d %d %d", &a, &b, &w);
add(a, b, w), add(b, a, w);
}
int min = 0x3f3f3f3f;
for(int i = 1; i <= p; i++){
head = 0, tail = 0;
memset(inQue, false, sizeof inQue);
memset(dist, 0x3f, sizeof dist);
if(h[i] == -1) continue; //最后有个3 5 5 的测试过不了 特判了一下
int res = spfa(i);
if(res < min) min = res;
}
printf("%d", min);
return 0;
}