#include <bits/stdc++.h>
using namespace std;
int cnt, par[((int)(5e5 + 5))][20 + 2], lv[((int)(5e5 + 5))],
    dsu[((int)(5e5 + 5))], up[((int)(5e5 + 5))], root[((int)(5e5 + 5))],
    u[((int)(5e5 + 5))], v[((int)(5e5 + 5))], w[((int)(5e5 + 5))];
long long int ans;
vector<int> adj[((int)(5e5 + 5))];
void getroot(int n, int p) {
  for (int i = 0; i < adj[n].size(); i++) {
    if (adj[n][i] != p) {
      root[adj[n][i]] = root[n];
      getroot(adj[n][i], n);
    }
  }
}
void dfs(int n) {
  for (int i = 0; i < adj[n].size(); i++) {
    if (adj[n][i] != par[n][0]) {
      par[adj[n][i]][0] = n;
      lv[adj[n][i]] = lv[n] + 1;
      dfs(adj[n][i]);
    }
  }
}
int lca(int a, int b) {
  if (lv[a] > lv[b]) swap(a, b);
  int i, p = lv[b] - lv[a];
  for (i = 0; p != 0; i++) {
    if (p & (1 << i)) {
      p -= (1 << i);
      b = par[b][i];
    }
  }
  if (a == b) return a;
  for (i = 20; i >= 0; i--) {
    if (par[a][i] != par[b][i]) {
      b = par[b][i];
      a = par[a][i];
    }
  }
  return par[a][0];
}
int findpar(int n) {
  if (dsu[n] == n) return n;
  return dsu[n] = findpar(dsu[n]);
}
int connect(int n, int l, int w) {
  if (up[n] != n) return up[n] = connect(up[n], l, w);
  if (lv[n] <= lv[l]) return n;
  if (w > 0) {
    ans += w;
    cnt--;
  }
  dsu[findpar(n)] = findpar(par[n][0]);
  return up[n] = connect(up[par[n][0]], l, w);
}
int main() {
  int n, k, m, i, j, a, b, l;
  scanf("%d %d %d", &n, &k, &m);
  for (i = 1; i <= n; i++) {
    dsu[i] = i;
    up[i] = i;
  }
  cnt = k;
  while (k--) {
    scanf("%d %d", &a, &b);
    adj[b].push_back(a);
    adj[a].push_back(b);
  }
  for (i = 1; i <= n; i++) {
    if (root[i] == 0) {
      root[i] = i;
      getroot(i, 0);
    }
  }
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &u[i], &v[i], &w[i]);
    if (findpar(root[u[i]]) != findpar(root[v[i]])) {
      dsu[findpar(root[u[i]])] = findpar(root[v[i]]);
      adj[v[i]].push_back(u[i]);
      adj[u[i]].push_back(v[i]);
      w[i] = -1;
    }
  }
  dfs(1);
  for (i = 1; i <= 20; i++) {
    for (j = 1; j <= n; j++) par[j][i] = par[par[j][i - 1]][i - 1];
  }
  for (i = 1; i <= n; i++) dsu[i] = i;
  for (i = 0; i < m; i++) {
    a = u[i];
    b = v[i];
    if (findpar(a) != findpar(b)) {
      l = lca(a, b);
      up[a] = connect(up[a], l, w[i]);
      up[b] = connect(up[b], l, w[i]);
    }
  }
  if (cnt > 0) ans = -1;
  printf("%lld\n", ans);
  return 0;
}
