#include <cstdio>
#include <cstring>
#include <vector>
#include <utility>
#include <set>
#include <algorithm>
using namespace std;

struct UnionFind {
    vector<int> node;
    UnionFind(int n) {
        node = vector<int>(n, -1);
    }
    int find(int x) {
        return node[x] < 0 ? x : node[x] = find(node[x]);
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return false;
        node[x] += node[y];
        node[y] = x;
        return true;
    }
    int size(int x) {
        return -node[find(x)];
    }
};

struct Edge {
    int from, to, cost;
    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
};

int main() {
    int N, M, K; scanf("%d%d%d", &N, &M, &K);
    vector<int> col(N);
    int num_unknown = 0;
    for(int i=0; i<N; i++) scanf("%d", &col[i]), num_unknown += (!col[i]);

    vector<Edge> edges;
    for(int i=0; i<M; i++) {
        int u, v, w; scanf("%d%d%d", &u, &v, &w);
        u--; v--;
        edges.push_back(Edge{u, v, w});
    }

    sort(edges.begin(), edges.end());
    UnionFind uf(N+K);

    long long int ans = 0, rest = K-1;
    for(int i=0; rest>0 && i<M; i++) {
        int u = edges[i].from, v = edges[i].to;
        int id_u = col[u] ? col[u] - 1 : K+u;
        int id_v = col[v] ? col[v] - 1 : K+v;
        if(uf.unite(id_u, id_v)) {
            ans += edges[i].cost;
            rest--;
        }
    }
    if(rest) printf("-1\n");
    else printf("%lld\n", ans);
    return 0;
}