#include<bits/stdc++.h>
using namespace std;
const int maxn = 10010;
const int INF = 0x3f3f3f3f;
bool Is_im[maxn];
int Map[maxn][maxn];
int main()
{
int n, m, K;
scanf("%d %d %d", &n, &m, &K);
for(int i = 1; i <= n; i++)
scanf("%d", &Is_im[i]);
memset(Map, 0x3f, sizeof(Map));
for(int i = 1; i <= n; i++)
Map[i][i] = 0;
for(int i = 0; i < m; i++){
int v1, v2, c;
scanf("%d %d %d", &v1, &v2, &c);
Map[v1][v2] = Map[v2][v1] = min(Map[v1][v2], c);
}
for(int k = 1; k <= n; k++){
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++)
if(Map[i][j] > Map[i][k]+Map[k][j])
Map[i][j] = Map[i][k] + Map[k][j];
}
}
priority_queue<int, vector<int>, greater<int> > p_q;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(Is_im[j] && Map[i][j] < INF){
p_q.push(Map[i][j]);
}
}
int KK = 0;
long long sum = 0;
while(!p_q.empty()){
int num = p_q.top();
p_q.pop();
sum += num;
KK++;
if(KK == K) break;
}
printf("%lld\n", sum);
while(!p_q.empty())
p_q.pop();
}
return 0;
}