#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 100005
#define MOD 1000
#define oo 1000000000000000007LL
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}
struct Edge {
    int u, v, w;
    bool inline operator < (const Edge &rhs) const {
        return w < rhs.w;
    }
};

struct DSU {
    vector<int> pset;
    DSU(int n) {
        pset.resize(n+1);
        fto(i, 1, n) pset[i] = i;
    }
    int findSet(int u) {
        return (pset[u] == u) ? u : pset[u] = findSet(pset[u]);
    }
    bool unionSet(int u, int v) {
        int p = findSet(u), q = findSet(v);
        if (p == q) return false;
        pset[p] = q;
        return true;
    }
};

int n, m, k, c[maxN], cnt;
Edge e[maxN];

int main () {
    scanf("%d%d%d", &n, &m, &k);
    fto(i, 1, n) scanf("%d", &c[i]);
    fto(i, 1, m) scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);

    if (k == 1) {
        puts("0");
        return 0;
    }
    cnt = k;
    fto(i, 1, n)
        if (c[i] == 0) c[i] = ++cnt;

    sort(e+1, e+m+1);
    ll ans = 0;
    int cntEdge = 0;
    DSU s(cnt);
//    fto(u, 1, n) printf("%d ", c[u]);
//    puts("");
    fto(i, 1, m) {
        if (s.unionSet(c[e[i].u], c[e[i].v])) {
            ans += e[i].w;
            ++cntEdge;
            if (cntEdge == k-1) {
                printf("%lld", ans);
                return 0;
            }
        }
    }

    puts("-1");

    return 0;
}
