#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<vector>
struct UF{
	int n;
	vector<int>parent,rank;
	UF(int n_=0):n(n_),parent(n_),rank(n_,1)
	{
		for(int i=0;i<n_;i++)parent[i]=i;
	}
	int find(int a){return parent[a]!=a?parent[a]=find(parent[a]):a;}
	bool same(int a,int b){return find(a)==find(b);}
	bool unite(int a,int b)
	{
		a=find(a),b=find(b);
		if(a==b)return false;
		if(rank[a]<rank[b])
		{
			parent[a]=b;
			rank[b]+=rank[a];
		}
		else
		{
			parent[b]=a;
			rank[a]+=rank[b];
		}
		return true;
	}
	int size(int a){return rank[find(a)];}
};
int N,M,K;
int c[1<<17];
vector<pair<int,pair<int,int> > >Es;
int main()
{
	cin>>N>>M>>K;
	for(int i=0;i<N;i++)cin>>c[i];
	for(int i=0;i<M;i++)
	{
		int a,b,w;cin>>a>>b>>w;
		a--,b--;
		Es.push_back(make_pair(w,make_pair(a,b)));
	}
	sort(Es.begin(),Es.end());
	long ans=0;
	UF uf(N+K);
	int ec=0;
	for(pair<int,pair<int,int> >e:Es)
	{
		int a=e.second.first,b=e.second.second;
		if(c[a]==0)a=K+a;
		else a=c[a]-1;
		if(c[b]==0)b=K+b;
		else b=c[b]-1;
		if(ec<K-1&&uf.unite(a,b))
		{
			ec++;
			ans+=e.first;
		}
	}
	cout<<(ec<K-1?-1:ans)<<endl;
}
