#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
#define SIZE 300001
class unionfind
{
public:
	int par[SIZE];
	int ran[SIZE];
	int ren[SIZE];
	void init()
	{
		for (int i = 0; i<SIZE; i++)
		{
			par[i] = i;
			ran[i] = 0;
			ren[i] = 1;
		}
	}
	int find(int a)
	{
		if (a == par[a])return a;
		else return par[a] = find(par[a]);
	}
	void unite(int a, int b)
	{
		a = find(a);
		b = find(b);
		if (a == b)return;
		if (ran[a]>ran[b])
		{
			par[b] = a;
			ren[a] += ren[b];
		}
		else
		{
			par[a] = b;
			ren[b] += ren[a];
		}
		if (ran[a] == ran[b])ran[b]++;
	}
};
unionfind uf;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<ll, pii>pi3;
int dat[111111];
int main()
{
	int num, way, col;
	scanf("%d%d%d", &num, &way, &col);
	uf.init();
	for (int i = 0; i < num; i++)scanf("%d", &dat[i]);
	vector<pi3>vec;
	for (int i = 0; i < way; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		za--, zb--;
		vec.push_back(make_pair(zc, make_pair(za,zb)));
	}
	sort(vec.begin(), vec.end());
	//reverse(vec.begin(), vec.end());
	int cnt = 0;
	ll ans = 0;
	for (int i = 0; i < way; i++)
	{
		if (cnt == col - 1)break;
		ll d = vec[i].first;
		int a = vec[i].second.first, b = vec[i].second.second;
		if (dat[a] == 0)a += 111111;
		else a = dat[a];
		if (dat[b] == 0)b += 111111;
		else b = dat[b];
		if (uf.find(a) != uf.find(b))uf.unite(a, b), ans += d, cnt++;
	}
	if (cnt < col - 1)printf("-1\n");
	else printf("%lld\n", ans);
}