#include <iostream>
#include <queue>
#include <vector>
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar()) w = ch == '-' ? -1 : 1;
for (; ch >= '0' && ch <= '9'; ch = getchar()) s = s * 10 + ch - '0';
return s * w;
}
vector < pair <int, int> > G[810];
int main() {
int N, P, C, f[810] = {}, x, y, a, cnt[810] = {};
N = read(), P = read(), C = read();
for (int i = 1; i <= N; i ++) {
int m;
m = read(), cnt[m] ++;
}
for (int i = 1; i <= C; i ++) {
x = read(), y = read(), a = read();
G[x].push_back({a, y}), G[y].push_back({a, y});
}
int ans = 191981000;
for (int i = 1; i <= P; i ++) {
priority_queue < pair <int, int> > que;
que.push({0, i});
bool vis[810] = {};
vis[0] = true;
for (int j = 1; j <= P; j ++) f[j] = 191981000;
f[i] = 0;
while (!que.empty()) {
int x = que.top().second;
que.pop();
if (vis[x]) continue;
vis[x] = true;
for (int j = 0; j < (int)G[x].size(); j ++) {
pair <int, int> v = G[x][j];
if (f[v.second] >= f[x] + v.first && !vis[v.second]) {
f[v.second] = f[x] + v.first;
que.push({f[v.second], v.second});
}
}
}
int sum = 0;
for (int j = 1; j <= P; j ++) {
sum += f[j] * cnt[j];
}
ans = min(ans, sum);
}
cout << ans;
}