#include <bits/stdc++.h>
using namespace std;
int n, p, c, a, b, d, u;
long long num[805], g[805][805];
int main()
{
memset(g, 0x3f, sizeof(g));
cin >> n >> p >> c;
for (int i = 1; i <= n; i++)
{
cin >> u;
num[u]++;
}
while (c--)
{
cin >> a >> b >> d;
g[a][b] = g[b][a] = d;
}
for (int k = 1; k <= p; k++)
{
for (int i = 1; i <= p; i++)
{
for (int j = 1; j <= p; j++)
{
if (i != j && j != k && k != i && g[i][k] != g[0][0] && g[k][j] != g[0][0] && g[i][j] > g[i][k] + g[k][j])
{
g[i][j] = g[i][k] + g[k][j];
}
}
}
}
long long ans = g[0][0];
for (int k = 1; k <= p; k++)
{
long long sum = 0;
for (int i = 1; i <= p; i++)
{
if (i == k)
continue;
sum += g[i][k] * num[i];
}
ans = min(ans, sum);
}
cout << ans;
return 0;
}