#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll P[202020], C[101010], K[101010];
ll S[101010], E[101010], V[101010];
ll n, m, k, t, ans, cnt;

ll find(ll p) { return p == P[p]? p : P[p] = find(P[p]); }

int main()
{
	int i, s, e;
	
	scanf("%lld%lld%lld", &n, &m, &k);
	
	t = k;
	for(i=1; i<=n; i++){
		scanf("%lld", C+i);
		if(C[i] == 0) C[i] = ++t;
	}
	
	for(i=1; i<=t; i++) P[i] = i;
	
	for(i=1; i<=m; i++){
		scanf("%lld%lld%lld", S+i, E+i, V+i);
		K[i] = i;
	}
	
	sort(K+1, K+m+1, [=](int ca, int cb){
		return V[ca] < V[cb];
	});
	
	for(i=1; i<=m; i++){
		s = find(C[S[K[i]]]);
		e = find(C[E[K[i]]]);
		if(s != e){
			P[s] = e;
			ans += V[K[i]];
			cnt ++;
		}
		
		if(cnt == k - 1) break;
	}
	
	if(i > m) printf("-1\n");
	else printf("%lld\n", ans);
	
	return 0;
}