#include <bits/stdc++.h>

#define VARNAME(x) #x
#define show(x) cerr << #x << " = " << x << endl

using namespace std;
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v)
{
    os << "sz:" << v.size() << "\n[";
    for (const auto& p : v) {
        os << p << ",";
    }
    os << "]\n";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}


constexpr ll MOD = (ll)1e9 + 7LL;

class DisjointSets
{
public:
    DisjointSets(const int v)
    {
        m_parent.resize(v);
        m_rank.resize(v);
        m_size.resize(v);
        for (int i = 0; i < v; i++) {
            m_parent[i] = i;
            m_rank[i] = 0;
            m_size[i] = 1;
        }
    }

    bool same(const int a, const int b)
    {
        return find(a) == find(b);
    }


    int find(const int a)
    {
        if (m_parent[a] == a) {
            return a;
        } else {
            return m_parent[a] = find(m_parent[a]);
        }
    }

    void unite(const int a_, const int b_)
    {
        const int a = find(a_);
        const int b = find(b_);
        if (a == b) {
            return;
        }
        if (m_rank[a] > m_rank[b]) {
            m_parent[b] = a;
            m_size[a] += m_size[b];
        } else {
            m_parent[a] = b;
            m_size[b] += m_size[a];
        }
        if (m_rank[a] == m_rank[b]) {
            m_rank[b]++;
        }
    }

    int getSize(const int a)
    {
        return m_size[m_parent[a]];
    }

private:
    vector<int> m_parent;
    vector<int> m_rank;
    vector<int> m_size;
};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> c(N);
    int zero = 0;
    for (int i = 0; i < N; i++) {
        cin >> c[i];
        if (c[i] == 0) {
            c[i] = K + zero;
            zero++;
        } else {
            c[i]--;
        }
    }
    vector<Edge> edge(M);
    for (int i = 0; i < M; i++) {
        int a, b;
        ll w;
        cin >> a >> b >> w;
        a--, b--;
        edge.push_back(Edge{c[a], c[b], w});
    }

    if (M < K - 1) {
        cout << -1 << endl;
        return 0;
    }


    constexpr ll INF = 1LL << 42;
    // for (int i = 1; i <= K; i++) {
    //     edge.push_back(Edge{0, i, INF});
    // }
    DisjointSets uf(K + zero);
    sort(edge.begin(), edge.end());
    vector<ll> use;
    int num = 0;
    for (const auto& e : edge) {
        const int u = e.from;
        const int v = e.to;
        const ll cost = e.cost;
        if (not uf.same(u, v)) {
            if (cost == INF) {
                num++;
            }
            use.push_back(cost);
            uf.unite(u, v);
        }
    }
    set<int> cp;
    for (int i = 0; i < K + zero; i++) {
        cp.insert(uf.find(i));
    }
    const int size = cp.size();
    for (int i = 0; i < size - 1; i++) {
        use.push_back(INF);
        num++;
    }

    if (num > zero) {
        cout << -1 << endl;
    } else {
        const ll sum = accumulate(use.begin(), use.end(), 0LL);
        sort(use.begin(), use.end(), greater<ll>{});
        const ll maxi = accumulate(use.begin(), use.begin() + zero, 0LL);
        cout << sum - maxi << endl;
    }

    return 0;
}


Measured memory_bytes: 14180