#include <bits/stdc++.h>
using namespace std;
template <class T>
T gi() {
  T x = 0;
  bool f = 0;
  char c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') f = 1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f ? -x : x;
}
const int N = 5e5 + 10;
vector<pair<int, int> > e[N];
struct node {
  int x, y, z;
};
vector<node> used;
int fa[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int Fa[N], g[N], dep[N];
void dfs(int u, int ff) {
  for (auto v : e[u]) {
    if (v.first == ff) continue;
    Fa[v.first] = u;
    dep[v.first] = dep[u] + 1;
    g[v.first] = v.second;
    dfs(v.first, u);
  }
}
int main() {
  int n = gi<int>(), k = gi<int>(), m = gi<int>();
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= k; i++) {
    int x = gi<int>(), y = gi<int>();
    fa[find(y)] = find(x);
    e[x].push_back(make_pair(y, 0));
    e[y].push_back(make_pair(x, 0));
  }
  for (int i = 1; i <= m; i++) {
    int x = gi<int>(), y = gi<int>(), z = gi<int>();
    if (find(x) == find(y)) {
      used.push_back((node){x, y, z});
      continue;
    }
    e[x].push_back(make_pair(y, z));
    e[y].push_back(make_pair(x, z));
    fa[find(y)] = find(x);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) fa[i] = i;
  long long ans = 0;
  for (auto E : used) {
    int x = E.x, y = E.y, z = E.z;
    while (x != y) {
      if (dep[x] < dep[y]) swap(x, y);
      if (!g[x]) {
        g[x] = z;
        ans += z;
      }
      fa[x] = find(Fa[x]);
      x = find(x);
    }
  }
  for (int i = 2; i <= n; i++)
    if (!g[i]) {
      puts("-1");
      return 0;
    }
  printf("%lld\n", ans);
  return 0;
}
