#include <bits/stdc++.h>
using namespace std;
const int N = 501000;
const int inf = 0x7fffffff;
int tim, n, k, m, ew[N];
int ffa[N], typ[N];
int fa[N], dep[N], siz[N], son[N], top[N], dfn[N];
int T[N << 2], tag[N << 2], id[N], seq[N];
long long sum;
vector<pair<int, int> > g[N];
int Find(int x) {
  if (ffa[x] == x) return x;
  return ffa[x] = Find(ffa[x]);
}
void Unite(int x, int y) {
  x = Find(x);
  y = Find(y);
  ffa[y] = x;
  return;
}
struct Node {
  int x, y, w;
  bool operator<(const Node& a) const { return w < a.w; }
} e[N];
void DFS(int x) {
  siz[x] = 1;
  int y;
  for (auto p : g[x]) {
    y = p.first;
    if (y == fa[x]) continue;
    dep[y] = dep[x] + 1;
    fa[y] = x;
    id[y] = p.second;
    DFS(y);
    siz[x] += siz[y];
    if (siz[son[x]] < siz[y]) son[x] = y;
  }
  return;
}
void RDFS(int x, int tp) {
  dfn[x] = ++tim;
  top[x] = tp;
  seq[tim] = id[x];
  if (!son[x]) return;
  RDFS(son[x], tp);
  int y;
  for (auto p : g[x]) {
    y = p.first;
    if (y == fa[x] || y == son[x]) continue;
    RDFS(y, y);
  }
  return;
}
void build(int x, int l, int r) {
  tag[x] = inf;
  if (l == r) {
    T[x] = inf;
    return;
  }
  int mid = l + r >> 1;
  build(x << 1, l, mid);
  build(x << 1 | 1, mid + 1, r);
  return;
}
void cov(int x, int l, int r, int L, int R, int d) {
  if (L <= l && r <= R) {
    tag[x] = min(tag[x], d), T[x] = min(T[x], d);
    return;
  }
  int mid = l + r >> 1;
  if (L <= mid) cov(x << 1, l, mid, L, R, d);
  if (R > mid) cov(x << 1 | 1, mid + 1, r, L, R, d);
  return;
}
void push(int x) {
  if (tag[x] == inf) return;
  tag[x << 1] = min(tag[x], tag[x << 1]);
  tag[x << 1 | 1] = min(tag[x], tag[x << 1 | 1]);
  T[x << 1] = min(tag[x], T[x << 1]);
  T[x << 1 | 1] = min(tag[x], T[x << 1 | 1]);
  tag[x] = inf;
  return;
}
void tdfs(int x, int l, int r) {
  if (l == r) {
    if (!seq[l]) return;
    if (sum == -1) return;
    if (T[x] == inf)
      sum = -1;
    else
      sum += T[x];
    return;
  }
  push(x);
  int mid = l + r >> 1;
  tdfs(x << 1, l, mid);
  tdfs(x << 1 | 1, mid + 1, r);
  return;
}
void linkcov(int x, int y, int w) {
  for (int fx = top[x], fy = top[y]; fx != fy; x = fa[fx], fx = top[x]) {
    if (dep[fx] < dep[fy]) swap(fx, fy), swap(x, y);
    cov(1, 1, n, dfn[fx], dfn[x], w);
  }
  if (dep[x] > dep[y]) swap(x, y);
  cov(1, 1, n, dfn[x] + 1, dfn[y], w);
  return;
}
int main() {
  cin >> n >> k >> m;
  for (int i = 1; i <= n; i++) ffa[i] = i;
  for (int x, y, i = 1; i <= k; i++) {
    scanf("%d%d", &x, &y);
    g[x].push_back(make_pair(y, i));
    g[y].push_back(make_pair(x, i));
    Unite(x, y);
  }
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].w);
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= m; i++) {
    if (Find(e[i].x) == Find(e[i].y))
      typ[i] = 1;
    else
      Unite(e[i].x, e[i].y), g[e[i].x].push_back(make_pair(e[i].y, 0)),
          g[e[i].y].push_back(make_pair(e[i].x, 0));
  }
  build(1, 1, n);
  dep[1] = 1;
  DFS(1);
  RDFS(1, 1);
  for (int i = 1; i <= m; i++)
    if (typ[i]) linkcov(e[i].x, e[i].y, e[i].w);
  tdfs(1, 1, n);
  cout << sum << endl;
  return 0;
}
