#include <bits/stdc++.h>
using namespace std;
const int BufferSize = 1 << 16;
char buffer[BufferSize], *front_head, *front_tail;
inline char GET_CHAR() {
  if (front_head == front_tail) {
    int l = fread(buffer, 1, BufferSize, stdin);
    front_tail = (front_head = buffer) + l;
    if (front_head == front_tail) return EOF;
  }
  return *front_head++;
}
inline int READ() {
  int x = 0, f = 1;
  char c = GET_CHAR();
  for (; !isdigit(c); c = GET_CHAR()) {
    if (c == EOF) return EOF;
    if (c == '-') f = -1;
  }
  for (; isdigit(c); c = GET_CHAR()) x = (((x << 2) + x) << 1) + c - '0';
  return x * f;
}
const int N = 500005, M = 1000005;
int pre[500005];
int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); }
const int Headsize = N, Edgesize = M;
int head[Headsize + 5], mal = 1;
struct edge {
  int nx, to;
} e[Edgesize + 5];
inline void addedge(int u, int v) {
  e[mal].to = v;
  e[mal].nx = head[u];
  head[u] = mal++;
}
int Eu[N], Ev[N], Ew[N], w;
int faz[N], dep[N], deg[N];
bool val[N];
long long res = 0;
void dfs(int u, int f) {
  dep[u] = dep[faz[u] = f] + 1;
  for (int i = head[u]; i; i = e[i].nx) {
    int v = e[i].to;
    if (v != f) dfs(v, u);
  }
  if (deg[u]) val[u] = 1, --deg[f], --deg[u];
}
int main() {
  int n, k, m, u, v;
  n = READ();
  k = READ();
  m = READ();
  for (int i = 1; i <= n; i++) pre[i] = i;
  for (int i = 0; i < k; i++) {
    addedge(u = READ(), v = READ());
    addedge(v, u);
    deg[u]++;
    deg[v]++;
    u = find(u);
    v = find(v);
    pre[u] = v;
  }
  for (int i = 0; i < m; i++) {
    Eu[i] = u = READ();
    Ev[i] = v = READ();
    Ew[i] = READ();
    u = find(u);
    v = find(v);
    if (u != v) {
      addedge(Eu[i], Ev[i]);
      addedge(Ev[i], Eu[i]);
      pre[u] = v;
      m--;
      i--;
    }
  }
  dep[1] = -1;
  dfs(1, 0);
  faz[1] = 1;
  for (int i = 1; i <= n; i++) pre[i] = i;
  for (int i = 0; i < m; i++) {
    u = find(Eu[i]);
    v = find(Ev[i]);
    w = Ew[i];
    while (u != v) {
      if (dep[u] < dep[v]) swap(u, v);
      if (val[u]) {
        val[u] = 0, res += w;
        if (--k == 0) {
          printf("%I64d\n", res);
          return 0;
        }
      }
      u = pre[u] = find(faz[u]);
    }
  }
  puts("-1");
}
