#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
int c[111111];
int vis[111111];
struct edg
{
	int x,y,v;
}ed[222222];
int pe;
bool operator <(const edg &x,const edg &y)
{
	return x.v<y.v;
}
int fa[111111];
int gf(int u)
{
	if(fa[u]==u)return u;
	return fa[u]=gf(fa[u]);
}
int la[111111];
int main()
{
	int n=io::F(),m=io::F(),k=io::F();
	for(register int i=1;i<=n;++i)vis[c[i]=io::F()]=1,la[c[i]]=i;
	int cnt=0;
	for(register int i=1;i<=n;++i)if(c[i]==0)++cnt;
	int cv=0;
	for(register int i=1;i<=k;++i)if(vis[i]==0)++cv;
	if(cv>cnt)
	{
		puts("-1");
		return 0;
	}
	int cc=cnt-cv;
	for(register int i=1;i<=m;++i)
		ed[i]=(edg){io::F(),io::F(),io::F()};
	pe=m;
	for(register int i=1;i<=n;++i)
		if(c[i]&&la[c[i]]!=i)ed[++pe]=(edg){i,la[c[i]],0};
	std::sort(ed+1,ed+pe+1);
	for(register int i=1;i<=n;++i)fa[i]=i;
	long long ans=0;
	for(register int i=1;cc!=n-1&&i<=pe;++i)
	{
		int t1=gf(ed[i].x),t2=gf(ed[i].y);
		if(t1==t2)continue;
		fa[t1]=t2;
		ans+=ed[i].v;
		++cc;
	}
	if(cc!=n-1){puts("-1");return 0;}
	printf("%lld\n",ans);
	return 0;
}


