#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int N, M, K, head[500005], fa[500005], tot;
struct node {
  int v, w, nxt;
} adj[500005 * 2];
int uu[500005], vv[500005], ww[500005], cntn;
void add(int u, int v, int w) {
  adj[++tot].nxt = head[u];
  adj[tot].v = v;
  adj[tot].w = w;
  head[u] = tot;
}
int fr(int u) {
  if (fa[u] == u)
    return u;
  else
    return fa[u] = fr(fa[u]);
}
long long ans;
int son[500005], shendu[500005], top[500005], chuo[500005], id[500005],
    size[500005], tim;
int shang[500005];
void dfs(int u) {
  size[u] = 1;
  for (int i = head[u]; i; i = adj[i].nxt) {
    int v = adj[i].v;
    int w = adj[i].w;
    if (v == fa[u]) continue;
    fa[v] = u;
    shendu[v] = shendu[u] + 1;
    dfs(v);
    size[u] += size[v];
    if (size[v] > size[son[u]]) son[u] = v;
  }
}
void dfs(int u, int zu, int pre) {
  chuo[u] = ++tim;
  id[tim] = u;
  top[u] = zu;
  shang[tim] = pre;
  if (son[u]) dfs(son[u], zu, 0);
  for (int i = head[u]; i; i = adj[i].nxt) {
    int v = adj[i].v;
    int w = adj[i].w;
    if (v == fa[u]) continue;
    if (v == son[u]) {
      shang[chuo[u] + 1] = w;
      continue;
    }
    dfs(v, v, w);
  }
}
int rt, ls[500005 * 2], rs[500005 * 2], tag[500005 * 2], zhi[500005 * 2], cnt;
int build(int l, int r) {
  int p = ++cnt;
  tag[p] = (1 << 30);
  if (l == r) {
    zhi[p] = shang[l];
    return p;
  }
  int m = (l + r) >> 1;
  ls[p] = build(l, m);
  rs[p] = build(m + 1, r);
  return p;
}
void change(int p, int l, int r, int ll, int rr, int x) {
  if (l == ll && r == rr) {
    tag[p] = min(tag[p], x);
    return;
  }
  int m = (l + r) >> 1;
  if (ll > m)
    change(rs[p], m + 1, r, ll, rr, x);
  else if (rr <= m)
    change(ls[p], l, m, ll, rr, x);
  else
    change(ls[p], l, m, ll, m, x), change(rs[p], m + 1, r, m + 1, rr, x);
}
void push(int p, int l, int r, int x) {
  x = min(x, tag[p]);
  if (l == r) {
    shang[l] = min(shang[l], x);
    return;
  }
  int m = (l + r) >> 1;
  push(ls[p], l, m, x);
  push(rs[p], m + 1, r, x);
}
int main() {
  scanf("%d%d%d", &N, &K, &M);
  for (int i = 1; i <= N; i++) fa[i] = i;
  for (int i = 1; i <= K; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add(u, v, 0);
    add(v, u, 0);
    fa[fr(u)] = fr(v);
  }
  for (int i = 1; i <= M; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    if (fr(u) != fr(v)) {
      add(u, v, w);
      add(v, u, w);
      fa[fr(u)] = fr(v);
    }
    uu[++cntn] = u;
    vv[cntn] = v;
    ww[cntn] = w;
  }
  for (int i = 1; i <= tot; i++) {
    if (adj[i].w == 0)
      adj[i].w = (1 << 30);
    else
      adj[i].w = 0;
  }
  for (int i = 1; i <= N; i++) fa[i] = 0;
  dfs(1);
  dfs(1, 1, 0);
  rt = build(1, N);
  for (int i = 1; i <= cntn; i++) {
    int u, v, w;
    u = uu[i];
    v = vv[i];
    w = ww[i];
    while (top[u] != top[v]) {
      if (shendu[top[u]] < shendu[top[v]]) swap(u, v);
      change(rt, 1, N, chuo[top[u]], chuo[u], w);
      u = fa[top[u]];
    }
    if (u == v) continue;
    if (shendu[u] < shendu[v]) swap(u, v);
    change(rt, 1, N, chuo[v] + 1, chuo[u], w);
  }
  push(rt, 1, N, (1 << 30));
  for (int i = 1; i <= N; i++) {
    if (shang[i] == (1 << 30)) {
      printf("-1");
      return 0;
    }
    ans += shang[i];
  }
  printf("%lld", ans);
  return 0;
}
