#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;
const string nyan("(=^・ω・^=)");

int N, M, K, c[100000], C[100000], t[100000], cnt;
bool b[100000];
ll res;
pair<int, pair<int, int>>p[100000];

int r(int x) {
	if (t[x] < 0)return x;
	return t[x] = r(t[x]);
}

bool u(int x, int y) {
	x = r(x);
	y = r(y);
	if (x == y)return false;
	if (t[x] < t[y]) {
		t[x] += t[y];
		t[y] = x;
	}
	else {
		t[y] += t[x];
		t[x] = y;
	}
	return true;
}

int main() {
	cin >> N >> M >> K;
	for (int i = 0; i < N; ++i) {
		cin >> c[i];
		--c[i];
	}
	for (int i = 0; i < M; ++i) {
		cin >> p[i].second.first >> p[i].second.second >> p[i].first;
		--p[i].second.first;
		--p[i].second.second;
	}
	sort(p, p + M);
	memset(t, -1, sizeof t);
	memset(C, -1, sizeof C);
	for (int i = 0; i < N; ++i) {
		if (c[i] >= 0) {
			if (C[c[i]] == -1) {
				C[c[i]] = i;
			}
			else {
				u(C[c[i]], i);
			}
		}
	}
	for (int i = 0; i < M; ++i) {
		if (u(p[i].second.first, p[i].second.second)) {
			++cnt;
			res += p[i].first;
			if (cnt == K - 1) {
				cout << res << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
}
