#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
struct edge {
	int a, b, cost;
};
vector<int> par;
int root(int x) {
	if (x == par[x]) return x;
	return par[x] = root(par[x]);
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M, K;
	cin >> N >> M >> K;
	vector<int> c(N);
	for (int i = 0; i < N; ++i) {
		cin >> c[i]; --c[i];
	}
	vector<edge> edges;
	for (int i = 0; i < M; ++i) {
		int a, b, w;
		cin >> a >> b >> w; --a, --b;
		edges.push_back(edge{ c[a] != -1 ? c[a] + N : a, c[b] != -1 ? c[b] + N : b, w });
	}
	sort(edges.begin(), edges.end(), [](edge e1, edge e2) { return e1.cost < e2.cost; });
	par.resize(N + K);
	for (int i = 0; i < N + K; ++i) par[i] = i;
	int comps = 0;
	long long ans = 0;
	for (edge e : edges) {
		if (root(e.a) != root(e.b)) {
			par[root(e.a)] = root(e.b);
			ans += e.cost;
			++comps;
			if (comps == K - 1) break;
		}
	}
	cout << (comps == K - 1 ? ans : -1) << '\n';
	return 0;
}