#include <bits/stdc++.h>
using namespace std;
static int N, K, M, G, U[500003], V[500003], W[500003], fa[500003], sup[500003],
    dep[500003];
static bool spe[500003];
static vector<pair<bool, int>> edge[500003];
static long long ans;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void dfs(int u, int f) {
  dep[u] = dep[sup[u] = f] + 1;
  for (auto v : edge[u])
    if (v.second != f) {
      spe[v.second] = v.first;
      dfs(v.second, u);
    }
}
int main() {
  scanf("%d%d%d", &N, &K, &M);
  for (int i = 1; i <= N; i++) fa[i] = i;
  for (int i = 0, x, y; i < K; i++) {
    scanf("%d%d", &x, &y);
    edge[x].push_back(make_pair(true, y));
    edge[y].push_back(make_pair(true, x));
    fa[find(x)] = find(y);
  }
  for (int i = 0; i < M; i++) {
    scanf("%d%d%d", &U[G], &V[G], &W[G]);
    int u = find(U[G]), v = find(V[G]);
    if (u != v) {
      edge[U[G]].push_back(make_pair(false, V[G]));
      edge[V[G]].push_back(make_pair(false, U[G]));
      fa[u] = v;
    } else
      G++;
  }
  dfs(1, 0);
  for (int i = 1; i <= N; i++) fa[i] = i;
  for (int i = 0; i < G; i++) {
    int u = find(U[i]), v = find(V[i]);
    while (u != v) {
      if (dep[u] < dep[v]) swap(u, v);
      ans += spe[u] ? W[i] : 0;
      u = fa[u] = find(sup[u]);
    }
  }
  for (int i = 1; i <= N; i++)
    for (auto v : edge[i])
      if (v.first && find(v.second) != find(i)) return puts("-1"), 0;
  printf("%lld\n", ans);
  return 0;
}
