#include <bits/stdc++.h>
int a[500010], b[500010], val[500010], f[500010], d[500010], res[500010], cnt,
    n, k, m, fa[500010], head[500010], tot;
int Find(int i) { return fa[i] == i ? i : fa[i] = Find(fa[i]); }
struct edge {
  int to, next, w;
} e[500010 * 2];
void add(int u, int v, int w) {
  e[++tot] = (edge){v, head[u], w};
  head[u] = tot;
}
void dfs(int u) {
  for (int i = head[u]; i; i = e[i].next)
    if (e[i].to != f[u]) {
      f[e[i].to] = u;
      d[e[i].to] = d[u] + 1;
      dfs(e[i].to);
    }
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  int u, v, w;
  for (int i = 1; i <= n; i++) fa[i] = i;
  while (k--) {
    scanf("%d%d", &u, &v);
    fa[Find(u)] = Find(v);
    add(u, v, 0);
    add(v, u, 0);
  }
  while (m--) {
    scanf("%d%d%d", &u, &v, &w);
    if (Find(u) == Find(v))
      a[cnt] = u, b[cnt] = v, val[cnt++] = w;
    else
      fa[Find(u)] = Find(v), add(u, v, 1), add(v, u, 1);
  }
  dfs(1);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 0; i < cnt; i++) {
    u = Find(a[i]), v = Find(b[i]);
    while (u != v) {
      if (d[u] > d[v])
        res[u] = val[i], fa[u] = Find(f[u]), u = fa[u];
      else
        res[v] = val[i], fa[v] = Find(f[v]), v = fa[v];
    }
  }
  long long ans = 0;
  for (u = 1; u <= n; u++)
    for (int i = head[u]; i; i = e[i].next)
      if (e[i].to == f[u] && !e[i].w) {
        if (fa[u] == u) {
          printf("-1\n");
          return 0;
        }
        ans += res[u];
      }
  printf("%lld\n", ans);
}
