#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 998244353;
void reduce(int &a) { a += a >> 31 & mod; }
int Mod(int x) { return x >= mod ? x - mod : x; }
int read() {
  int x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ 48);
  return x * f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
const int N = 500010, M = N;
int n, m, k;
;
struct edge {
  int nxt, to, w;
} e[M << 1];
int head[N], ecnt = 1;
void add(int u, int v, long long w = 0) {
  e[++ecnt].w = w, e[ecnt].to = v, e[ecnt].nxt = head[u];
  head[u] = ecnt;
}
void add_edge(int u, int v, long long w = 0) {
  add(u, v, w), add(v, u, w * 1);
};
struct Edge {
  int u, v, w;
} E[M << 1];
int f[N];
int getf(int u) { return f[u] == u ? u : f[u] = getf(f[u]); }
int fa[N], dep[N], c[N];
void dfs(int u) {
  dep[u] = dep[fa[u]] + 1;
  for (int i = head[u], v; i; i = e[i].nxt)
    if ((v = e[i].to) != fa[u]) fa[v] = u, c[v] = e[i].w, dfs(v);
}
void build() {
  for (int i = 1; i <= n; i++) f[i] = i;
  int cnt = 0;
  for (int i = 1; i <= m + k && cnt < n - 1; i++) {
    int fu = getf(E[i].u), fv = getf(E[i].v);
    if (fu ^ fv) add_edge(E[i].u, E[i].v, E[i].w), cnt++, f[fu] = fv;
  }
  dfs(1);
}
int num;
long long ans;
int main() {
  n = read(), k = read(), m = read();
  for (int i = 1; i <= k; i++) E[i] = {read(), read(), 0};
  for (int i = k + 1; i <= m + k; i++)
    E[i].u = read(), E[i].v = read(), E[i].w = read();
  build();
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = k + 1; i <= m + k; i++) {
    int u = getf(E[i].u), v = getf(E[i].v), w = E[i].w;
    while (u ^ v) {
      if (dep[u] < dep[v]) swap(u, v);
      if (!c[u]) ans += w, num++;
      f[u] = getf(fa[u]), u = getf(u);
    }
  }
  if (num < k) ans = -1;
  print(ans), putchar('\n');
  return 0;
}
