#include <bits/stdc++.h>
using namespace std;
const long long N = 1110000, inf = 1e15;
long long n, k, m, cnt, idx, tot;
long long f[N], head[N], ans[N];
long long dep[N], sz[N], fa[N], son[N], d[N];
long long id[N], top[N], pre[N];
long long v[N], nxt[N], w[N];
long long maxn[N * 4], flag[N * 4];
long long x[N], y[N], w_[N], judge[N];
void add(long long u_, long long v_, long long _w) {
  v[cnt] = v_, nxt[cnt] = head[u_], w[cnt] = _w, head[u_] = cnt++;
  v[cnt] = u_, nxt[cnt] = head[v_], w[cnt] = _w, head[v_] = cnt++;
}
long long find(long long x) { return x == f[x] ? x : f[x] = find(f[x]); }
void dfs1(long long u, long long father, long long depth) {
  dep[u] = depth, fa[u] = father, sz[u] = 1;
  for (long long i = head[u]; ~i; i = nxt[i]) {
    if (v[i] == father) continue;
    d[v[i]] = w[i];
    dfs1(v[i], u, depth + 1);
    sz[u] += sz[v[i]];
    if (sz[son[u]] < sz[v[i]]) son[u] = v[i];
  }
}
void dfs2(long long u, long long t) {
  id[u] = ++idx, top[u] = t, pre[idx] = u;
  if (son[u]) dfs2(son[u], t);
  for (long long i = head[u]; ~i; i = nxt[i]) {
    if (v[i] == son[u] || v[i] == fa[u]) continue;
    dfs2(v[i], v[i]);
  }
}
void pushup(long long root) {
  maxn[root] = max(maxn[root << 1], maxn[root << 1 | 1]);
  return;
}
void pushdown(long long root) {
  if (!flag[root]) return;
  if (flag[root] <= maxn[root << 1]) {
    maxn[root << 1] = flag[root], flag[root << 1] = flag[root];
  }
  if (flag[root] <= maxn[root << 1 | 1]) {
    maxn[root << 1 | 1] = flag[root], flag[root << 1 | 1] = flag[root];
  }
  flag[root] = 0;
}
void build(long long root, long long l, long long r) {
  if (l == r) {
    maxn[root] = d[pre[l]];
    return;
  }
  long long mid = l + r >> 1;
  build(root << 1, l, mid);
  build(root << 1 | 1, mid + 1, r);
  pushup(root);
}
void update(long long root, long long l, long long r, long long xl,
            long long xr, long long d) {
  if (d > maxn[root]) return;
  if (l == xl && r == xr) {
    maxn[root] = d;
    flag[root] = d;
    return;
  }
  pushdown(root);
  long long mid = l + r >> 1;
  if (xr <= mid)
    update(root * 2, l, mid, xl, xr, d);
  else if (xl > mid)
    update(root * 2 + 1, mid + 1, r, xl, xr, d);
  else {
    update(root * 2, l, mid, xl, mid, d);
    update(root * 2 + 1, mid + 1, r, mid + 1, xr, d);
  }
  pushup(root);
}
void update_path(long long u, long long v, long long d) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    update(1, 1, n, id[top[u]], id[u], d);
    u = fa[top[u]];
  }
  if (u == v) return;
  if (dep[u] < dep[v]) swap(u, v);
  update(1, 1, n, id[v] + 1, id[u], d);
}
long long lca(long long u, long long v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    u = fa[top[u]];
  }
  if (dep[u] < dep[v])
    return u;
  else
    return v;
}
void query(long long root, long long l, long long r) {
  if (l == r) {
    ans[pre[l]] = maxn[root];
    return;
  }
  pushdown(root);
  long long mid = l + r >> 1;
  query(root << 1, l, mid);
  query(root << 1 | 1, mid + 1, r);
}
signed main() {
  scanf("%lld%lld%lld", &n, &k, &m);
  memset(head, -1, sizeof head);
  for (long long i = 1; i <= n; i++) f[i] = i;
  for (long long i = 1; i <= k; i++) {
    long long x_, y_;
    scanf("%lld%lld", &x_, &y_);
    if (find(x_) != find(y_)) {
      f[find(x_)] = find(y_);
      add(x_, y_, inf);
    }
  }
  for (long long i = 1; i <= m; i++) {
    scanf("%lld%lld%lld", &x[i], &y[i], &w_[i]);
    if (find(x[i]) != find(y[i])) {
      f[find(x[i])] = find(y[i]);
      add(x[i], y[i], 0);
      judge[i] = 1;
    }
  }
  dfs1(1, 1, 1);
  dfs2(1, 1);
  build(1, 1, n);
  for (long long i = 1; i <= m; i++) {
    if (!judge[i]) {
      long long t = lca(x[i], y[i]);
      update_path(x[i], t, w_[i]);
      update_path(y[i], t, w_[i]);
    }
  }
  query(1, 1, n);
  for (long long i = 1; i <= n; i++)
    if (ans[i] == inf) {
      printf("-1");
      return 0;
    } else
      ans[i] += ans[i - 1];
  printf("%lld", ans[n]);
}
