#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
const int INF = (long long)1e9 + 5;
struct DSU {
  int N, pa[MAXN];
  void init(int _N) {
    N = _N;
    for (int i = 1; i <= N; i++) {
      pa[i] = i;
    }
  }
  int find(int x) { return pa[x] == x ? x : pa[x] = find(pa[x]); }
  bool merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    pa[y] = x;
    return true;
  }
} dsu;
struct Edge {
  int a, b, w;
};
int N, K, M, from[MAXN], pa[MAXN], st[MAXN], ed[MAXN], timer = 0;
vector<int> G[MAXN];
vector<Edge> es;
void dfs(int v, int p) {
  pa[v] = p;
  st[v] = ++timer;
  for (int id : G[v]) {
    int to = es[id].a ^ es[id].b ^ v;
    if (to == p) continue;
    from[to] = id;
    dfs(to, v);
  }
  ed[v] = timer;
}
bool is_anc(int a, int b) { return st[a] <= st[b] && ed[b] <= ed[a]; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K >> M;
  dsu.init(N);
  for (int i = 0; i < K; i++) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(i);
    G[y].push_back(i);
    es.push_back({x, y, -1});
    dsu.merge(x, y);
  }
  for (int i = 0; i < M; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    if (dsu.merge(x, y)) {
      G[x].push_back(i + K);
      G[y].push_back(i + K);
    }
    es.push_back({x, y, w});
  }
  dfs(1, 1);
  dsu.init(N);
  for (int i = K; i < es.size(); i++) {
    int a = dsu.find(es[i].a), b = dsu.find(es[i].b);
    while (!is_anc(a, b)) {
      dsu.merge(pa[a], a);
      if (es[from[a]].w == -1) {
        es[from[a]].w = es[i].w;
      }
      a = dsu.find(a);
    }
    swap(a, b);
    while (!is_anc(a, b)) {
      dsu.merge(pa[a], a);
      if (es[from[a]].w == -1) {
        es[from[a]].w = es[i].w;
      }
      a = dsu.find(a);
    }
  }
  long long ans = 0;
  for (int i = 0; i < K; i++) {
    ans += es[i].w;
    if (es[i].w == -1) {
      cout << -1 << '\n';
      return 0;
    }
  }
  cout << ans << "\n";
  return 0;
}
