#include <bits/stdc++.h>
using namespace std;
const int N = 5 * 1e5 + 100;
int n, k, m, f[N], fa[N], sz[N], son[N], dfn[N], cnt, de[N];
int top[N], tr[N], w, vi[N];
int tot, first[N], nxt[N * 2], point[N * 2];
struct edge {
  int u, v, w;
} q[N];
struct node {
  int tag, MAX[2];
  inline void add(int x) {
    if (x == MAX[0]) return;
    if (x > MAX[0])
      MAX[1] = MAX[0], MAX[0] = x;
    else if (x > MAX[1])
      MAX[1] = x;
  }
} sh[N * 4];
int find(int x) { return x == f[x] ? f[x] : f[x] = find(f[x]); }
inline int read() {
  int f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * f;
}
inline void ckmin(int &a, int b) { a = ((a < b) ? a : b); }
inline void ckmax(int &a, int b) { a = ((a > b) ? a : b); }
inline void merge(int a, int b) {
  int fax = find(a), fay = find(b);
  if (fax == fay) return;
  f[fax] = fay;
}
inline void add_edge(int x, int y) {
  nxt[++tot] = first[x];
  first[x] = tot;
  point[tot] = y;
}
void dfs(int x, int father) {
  sz[x] = 1;
  fa[x] = father;
  for (int i = first[x]; i != -1; i = nxt[i]) {
    int u = point[i];
    if (u == fa[x]) continue;
    if (i / 2 >= k) vi[u] = 1;
    de[u] = de[x] + 1;
    dfs(u, x);
    sz[x] += sz[u];
    if (sz[son[x]] < sz[u]) son[x] = u;
  }
}
void dfs1(int x, int t) {
  top[x] = t;
  dfn[x] = ++cnt;
  tr[cnt] = x;
  if (son[x]) dfs1(son[x], t);
  for (int i = first[x]; i != -1; i = nxt[i]) {
    int u = point[i];
    if (u == son[x] || u == fa[x]) continue;
    dfs1(u, u);
  }
}
inline void pushup(int x) {
  sh[x].MAX[0] = sh[x + x].MAX[0];
  sh[x].MAX[1] = sh[x + x].MAX[1];
  sh[x].add(sh[x + x + 1].MAX[0]), sh[x].add(sh[x + x + 1].MAX[1]);
}
inline void upd(int x, int v) {
  if (sh[x].MAX[0] <= v) return;
  sh[x].MAX[0] = v;
  ckmin(sh[x].tag, v);
}
inline void pushdown(int x) {
  if (sh[x].tag != 0x3f3f3f3f) {
    upd(x + x, sh[x].tag);
    upd(x + x + 1, sh[x].tag);
    sh[x].tag = 0x3f3f3f3f;
  }
}
void build(int x, int l, int r) {
  sh[x].MAX[0] = 0x3f3f3f3f;
  sh[x].MAX[1] = -0x3f3f3f3f;
  sh[x].tag = 0x3f3f3f3f;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(x + x, l, mid);
  build(x + x + 1, mid + 1, r);
}
void modify(int x, int l, int r, int v) {
  if (v >= sh[x].MAX[0]) return;
  if (v > sh[x].MAX[1]) {
    upd(x, v);
    return;
  }
  if (l == r) return;
  int mid = (l + r) >> 1;
  pushdown(x);
  modify(x + x, l, mid, v);
  modify(x + x + 1, mid + 1, r, v);
  pushup(x);
}
void change(int x, int l, int r, int ll, int rr, int v) {
  if (v >= sh[x].MAX[0]) return;
  if (ll <= l && rr >= r) {
    modify(x, l, r, v);
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(x);
  if (ll <= mid) change(x + x, l, mid, ll, rr, v);
  if (rr > mid) change(x + x + 1, mid + 1, r, ll, rr, v);
  pushup(x);
}
long long ans;
void print(int x, int l, int r) {
  if (l == r) {
    if (vi[tr[l]]) return;
    if (sh[x].MAX[0] == 0x3f3f3f3f) {
      printf("-1\n");
      exit(0);
    }
    ans += sh[x].MAX[0];
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(x);
  print(x + x, l, mid);
  print(x + x + 1, mid + 1, r);
}
void change_path(int x, int y, int w) {
  while (top[x] != top[y]) {
    if (de[top[x]] > de[top[y]]) swap(x, y);
    change(1, 1, n, dfn[top[y]], dfn[y], w);
    y = fa[top[y]];
  }
  if (dfn[x] > dfn[y]) swap(x, y);
  if (dfn[y] > dfn[x]) change(1, 1, n, dfn[x] + 1, dfn[y], w);
}
signed main() {
  tot = -1;
  memset(first, -1, sizeof(first));
  n = read();
  k = read();
  m = read();
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= k; i++) {
    int u = read(), v = read();
    add_edge(u, v);
    add_edge(v, u);
    merge(u, v);
  }
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read(), W = read();
    if (find(u) == find(v))
      q[++w] = (edge){u, v, W};
    else
      add_edge(u, v), add_edge(v, u), merge(u, v);
  }
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) {
      dfs(i, 0);
      dfs1(i, i);
      vi[i] = 1;
    }
  build(1, 1, n);
  for (int i = 1; i <= w; i++) change_path(q[i].u, q[i].v, q[i].w);
  print(1, 1, n);
  printf("%lld\n", ans);
}
