#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e6 + 100;
const long long inf = 0x3f3f3f3f;
const long long iinf = 1 << 30;
const long long linf = 2e18;
const long long mod = 998244353;
const double eps = 1e-7;
template <class T = long long>
T chmin(T &a, T b) {
  return a = min(a, b);
}
template <class T = long long>
T chmax(T &a, T b) {
  return a = max(a, b);
}
template <class T = long long>
T read() {
  T f = 1, a = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    a = (a << 3) + (a << 1) + ch - '0';
    ch = getchar();
  }
  return a * f;
}
long long n, m, k, tot;
struct node {
  long long u, v, val, typ;
  friend bool operator<(node a, node b) { return a.val < b.val; }
} e[maxn];
vector<pair<long long, long long> > edge[maxn];
long long fa[maxn], used[maxn], rfa[maxn], val[maxn], dep[maxn], ans;
void init() {
  for (long long i = (1); i <= (n); ++i) fa[i] = i;
}
long long getfa(long long a) { return a == fa[a] ? a : fa[a] = getfa(fa[a]); }
void solve_mst() {
  sort(e + 1, e + tot + 1);
  init();
  long long sum = 0;
  for (long long i = (1); i <= (tot); ++i) {
    long long u = e[i].u, v = e[i].v, t = e[i].typ;
    u = getfa(u), v = getfa(v);
    if (u != v)
      used[i] = 1, fa[u] = v, edge[e[i].u].push_back(make_pair(e[i].v, t)),
      edge[e[i].v].push_back(make_pair(e[i].u, t)), sum++;
    if (sum == n - 1) return;
  }
}
void dfs(long long now, long long fa) {
  for (pair<long long, long long> to : edge[now]) {
    if (to.first == fa) continue;
    rfa[to.first] = now;
    val[to.first] = to.second;
    dep[to.first] = dep[now] + 1;
    dfs(to.first, now);
  }
}
void modify(long long u, long long v, long long w) {
  u = getfa(u), v = getfa(v);
  while (u != v) {
    if (dep[v] > dep[u]) swap(u, v);
    ans += val[u] * w;
    fa[u] = rfa[u];
    u = getfa(u);
  }
}
void solve() {
  init();
  for (long long i = (1); i <= (tot); ++i) {
    if (used[i]) continue;
    modify(e[i].u, e[i].v, e[i].val);
  }
  for (long long i = (2); i <= (n); ++i)
    if (val[i] && getfa(i) == i) ans = -1;
}
signed main() {
  n = read(), k = read(), m = read();
  for (long long i = (1); i <= (k); ++i) {
    long long u = read(), v = read();
    e[++tot] = (node){u, v, 0, 1};
  }
  for (long long i = (1); i <= (m); ++i) {
    long long u = read(), v = read(), w = read();
    e[++tot] = (node){u, v, w, 0};
  }
  solve_mst();
  dfs(1, 0);
  solve();
  printf("%lld\n", ans);
  return 0;
}
