#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long SUM = 0, ff = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') ff = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    SUM = (SUM << 3) + (SUM << 1) + (ch ^ 48);
    ch = getchar();
  }
  return SUM * ff;
}
const int N = 1000010;
const long long inf = 1ll << 50;
int n, m, k;
long long ans[N], ANS;
int dsu[N];
inline int find(int x) { return dsu[x] == x ? x : dsu[x] = find(dsu[x]); }
struct E {
  int u, v;
  long long w;
} g[N];
struct edge {
  int nxt, to;
  long long w;
} e[N << 1];
int h[N], cnte = 1;
inline void addedge(int u, int v, long long w) {
  e[++cnte] = (edge){h[u], v, w}, h[u] = cnte;
}
int size[N], fa[N], dep[N], son[N], top[N];
int dfn[N], id[N], Time;
long long data[N];
bool choose[N << 1];
inline void dfs1(int u, int fu) {
  fa[u] = fu;
  dep[u] = dep[fu] + 1;
  size[u] = 1;
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fu) continue;
    data[v] = e[i].w;
    dfs1(v, u);
    size[u] += size[v];
    if (size[v] > size[son[u]]) son[u] = v;
  }
}
inline void dfs2(int u, int tp) {
  dfn[u] = ++Time;
  id[Time] = u;
  top[u] = tp;
  if (son[u]) dfs2(son[u], tp);
  for (int i = h[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa[u] || v == son[u]) continue;
    dfs2(v, v);
  }
}
struct segment {
  long long val, tag;
} tree[N << 2];
inline void pushup(int rt) {
  tree[rt].val = max(tree[(rt << 1)].val, tree[((rt << 1) | 1)].val);
}
inline void pushdown(int rt) {
  if (!tree[rt].tag) return;
  if (tree[rt].tag <= tree[(rt << 1)].val) {
    tree[(rt << 1)].val = tree[rt].tag;
    tree[(rt << 1)].tag = tree[rt].tag;
  }
  if (tree[rt].tag <= tree[((rt << 1) | 1)].val) {
    tree[((rt << 1) | 1)].val = tree[rt].tag;
    tree[((rt << 1) | 1)].tag = tree[rt].tag;
  }
  tree[rt].tag = 0;
}
inline void build(int rt, int l, int r) {
  if (l == r) {
    tree[rt].val = data[id[l]];
    return;
  }
  int mid = (l + r) >> 1;
  build((rt << 1), l, mid);
  build(((rt << 1) | 1), mid + 1, r);
  pushup(rt);
}
inline void modify(int rt, int l, int r, int L, int R, long long v) {
  if (v > tree[rt].val) return;
  if (L <= l && r <= R) {
    tree[rt].val = v;
    tree[rt].tag = v;
    return;
  }
  pushdown(rt);
  int mid = (l + r) >> 1;
  if (L <= mid) modify((rt << 1), l, mid, L, R, v);
  if (R > mid) modify(((rt << 1) | 1), mid + 1, r, L, R, v);
  pushup(rt);
}
inline void updata(int x, int y, long long v) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    modify(1, 1, n, dfn[top[x]], dfn[x], v);
    x = fa[top[x]];
  }
  if (x == y) return;
  if (dep[x] < dep[y]) swap(x, y);
  modify(1, 1, n, dfn[y] + 1, dfn[x], v);
}
inline int getlca(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  return (dep[x] < dep[y]) ? x : y;
}
inline void query(int rt, int l, int r) {
  if (l == r) {
    ans[id[l]] = tree[rt].val;
    return;
  }
  pushdown(rt);
  int mid = (l + r) >> 1;
  query((rt << 1), l, mid);
  query(((rt << 1) | 1), mid + 1, r);
}
int main() {
  n = read(), k = read(), m = read();
  for (int i = 1; i <= n; i++) dsu[i] = i;
  for (int i = 1; i <= k; i++) {
    int x = read(), y = read();
    int fx = find(x), fy = find(y);
    if (fx != fy) {
      dsu[fx] = fy;
      addedge(x, y, inf);
      addedge(y, x, inf);
    }
  }
  for (int i = 1; i <= m; i++) {
    g[i].u = read(), g[i].v = read(), g[i].w = read();
    int fu = find(g[i].u), fv = find(g[i].v);
    if (fu != fv) {
      dsu[fu] = fv;
      addedge(g[i].u, g[i].v, 0);
      addedge(g[i].v, g[i].u, 0);
      choose[i] = 1;
    }
  }
  dfs1(1, 0), dfs2(1, 1);
  build(1, 1, n);
  for (int i = 1; i <= m; i++)
    if (!choose[i]) {
      int lca = getlca(g[i].u, g[i].v);
      updata(g[i].u, lca, g[i].w);
      updata(g[i].v, lca, g[i].w);
    }
  query(1, 1, n);
  for (int i = 1; i <= n; i++) {
    if (ans[i] == inf) {
      puts("-1");
      return 0;
    }
    ANS += ans[i];
  }
  printf("%lld\n", ANS);
  return 0;
}
