#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int inf = 1e9 + 7;
struct edge_t {
  int u, v, w;
} e[N];
int n, m, q, f[N], tag[N], depth[N], value[N], parent[N];
vector<pair<int, int>> adj[N];
int find(int v) {
  if (v == f[v]) return v;
  return f[v] = find(f[v]);
}
void dfs(int v) {
  for (auto u : adj[v]) {
    if (u.first != parent[v]) {
      parent[u.first] = v;
      value[u.first] = u.second;
      depth[u.first] = depth[v] + 1;
      dfs(u.first);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q >> m;
  for (int i = 1; i <= q; ++i) cin >> e[i].u >> e[i].v;
  for (int i = 1; i <= m; ++i) cin >> e[i + q].u >> e[i + q].v >> e[i + q].w;
  for (int i = 1; i <= n; ++i) f[i] = i;
  for (int i = 1; i <= m + q; ++i) {
    if (find(e[i].u) != find(e[i].v)) {
      f[find(e[i].u)] = find(e[i].v);
      adj[e[i].u].emplace_back(e[i].v, e[i].w);
      adj[e[i].v].emplace_back(e[i].u, e[i].w);
    }
  }
  dfs(1);
  for (int i = 1; i <= n; ++i) {
    f[i] = i;
    tag[i] = inf;
  }
  for (int i = 1; i <= m; ++i) {
    int x = find(e[i + q].u), y = find(e[i + q].v), w = e[i + q].w;
    while (x != y) {
      if (depth[x] >= depth[y]) {
        tag[x] = w;
        f[x] = parent[x];
        x = find(x);
      } else {
        tag[y] = w;
        f[y] = parent[y];
        y = find(y);
      }
    }
  }
  long long ans = 0;
  for (int i = 2; i <= n; ++i) {
    if (!value[i]) {
      if (tag[i] == inf) return (cout << -1), 0;
      ans += tag[i];
    }
  }
  return (cout << ans), 0;
}
