#include <bits/stdc++.h>
using namespace std;
vector<int> mat[500010];
int lev[500010], n, bap[500010], val[500010], pa[500010];
struct edge {
  int u, v, w;
};
edge ami[500010], tmi[500010];
int k, m;
void initDsu() {
  for (int i = 1; i <= n; i++) pa[i] = i;
}
int finPa(int p) { return (pa[p] == p) ? p : (pa[p] = finPa(pa[p])); }
int mergeNode(int u, int v) {
  int r1 = finPa(u), r2 = finPa(v);
  if (r1 == r2) return 0;
  pa[r1] = r2;
  return 1;
}
void dfs(int p, int pa) {
  for (auto x : mat[p]) {
    if (x == pa) continue;
    bap[x] = p;
    lev[x] = lev[p] + 1;
    dfs(x, p);
  }
  return;
}
class cmp {
 public:
  bool operator()(edge x, edge y) { return x.w < y.w; }
};
void updateNode(int u, int v, int V) {
  if (u == v) return;
  if (lev[u] < lev[v]) swap(u, v);
  val[u] = min(val[u], V);
  mergeNode(u, bap[u]);
  updateNode(finPa(u), v, V);
  return;
}
int main() {
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i <= k - 1; i++)
    scanf("%d %d", &ami[i].u, &ami[i].v), ami[i].w = 0;
  for (int i = 0; i <= m - 1; i++)
    scanf("%d %d %d", &tmi[i].u, &tmi[i].v, &tmi[i].w);
  sort(tmi, tmi + m, cmp());
  initDsu();
  for (int i = 0; i <= k + m - 1; i++) {
    edge p;
    if (i < k)
      p = ami[i];
    else
      p = tmi[i - k];
    if (mergeNode(p.u, p.v)) {
      mat[p.u].push_back(p.v);
      mat[p.v].push_back(p.u);
    }
  }
  dfs(1, 1);
  initDsu();
  for (int i = 1; i <= n; i++) val[i] = 1e9 + 1;
  for (int i = 0; i <= m - 1; i++) {
    edge p = tmi[i];
    updateNode(p.u, p.v, p.w);
  }
  long long prin = 0;
  for (int i = 0; i <= k - 1; i++) {
    edge p = ami[i];
    if (bap[p.v] == p.u) swap(p.u, p.v);
    if (val[p.u] == (1e9 + 1)) {
      printf("-1");
      return 0;
    }
    prin = (long long)prin + val[p.u];
  }
  printf("%I64d", prin);
  return 0;
}
