#include <bits/stdc++.h>
using namespace std;
const long long MN = 5e5 + 100;
vector<long long> v[MN];
long long ufind[MN];
long long find(long long a) {
  if (ufind[a] == a) return a;
  return ufind[a] = find(ufind[a]);
}
void merge(long long a, long long b) { ufind[find(a)] = find(b); }
long long node_id[MN];
long long id = 0;
vector<pair<long long, long long> > qaq[MN];
long long ans = 0;
double ans2 = 0;
bool used[MN];
void f(long long x, set<pair<long long, long long> >& st) {
  used[x] = 1;
  set<pair<long long, long long> > st1;
  for (long long i = 0; i < qaq[x].size(); ++i) {
    st1.insert(qaq[x][i]);
  }
  for (auto y : v[x]) {
    if (!used[y]) {
      set<pair<long long, long long> > st2;
      f(y, st2);
      long long to_add = 1e17;
      if (st2.size()) {
        auto x = *st2.begin();
        to_add = min(to_add, x.first);
      }
      ans += to_add;
      ans2 += to_add;
      if (st2.size() > st1.size()) {
        swap(st1, st2);
      }
      for (auto x : st2) {
        if (st1.count(x)) {
          st1.erase(x);
          continue;
        }
        st1.insert(x);
      }
    }
  }
  swap(st, st1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long n, k, m;
  cin >> n >> k >> m;
  vector<pair<long long, long long> > our_edges;
  for (long long i = 0; i < k; ++i) {
    long long a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
    our_edges.push_back({a, b});
  }
  vector<vector<long long> > fe;
  for (long long i = 0; i < m; ++i) {
    long long a, b, w;
    cin >> a >> b >> w;
    fe.push_back({w, a, b});
  }
  sort(fe.begin(), fe.end());
  for (long long i = 0; i < MN; ++i) {
    ufind[i] = i;
  }
  for (long long i = 0; i < k; ++i) {
    merge(our_edges[i].first, our_edges[i].second);
  }
  long long to_remove = 0;
  for (long long i = 0; i < fe.size(); ++i) {
    long long a, b, w;
    a = fe[i][1];
    b = fe[i][2];
    w = fe[i][0];
    if (find(a) != find(b)) {
      v[a].push_back(b);
      v[b].push_back(a);
      to_remove += w;
      merge(a, b);
    }
    qaq[a].push_back({w, i});
    qaq[b].push_back({w, i});
  }
  set<pair<long long, long long> > st;
  f(1, st);
  if (ans2 > 1e16) {
    cout << -1 << endl;
  } else {
    cout << ans - to_remove << endl;
  }
}
