#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const int Log = 21;
const long long INF = 1e15;
pair<int, int> g[N], f[N];
int w[N], lab[N], d[N], nxt[N];
int n, m, k, tp, E;
bool choose[N];
int par[N][Log];
vector<int> e[N];
long long rz[N];
int root(int u) {
  if (lab[u] < 0) return u;
  return lab[u] = root(lab[u]);
}
bool Union(int u, int v) {
  int l1 = root(u), l2 = root(v);
  if (l1 == l2) return false;
  if (lab[l1] > lab[l2]) swap(l1, l2);
  lab[l1] += lab[l2];
  lab[l2] = l1;
  return true;
}
void dfs(int u, int p = 0) {
  for (auto v : e[u])
    if (v != p) {
      par[v][0] = u;
      d[v] = d[u] + 1;
      dfs(v, u);
    }
}
int lca(int u, int v) {
  if (d[u] < d[v]) swap(u, v);
  for (int lg = 20; lg >= 0; --lg)
    if (d[par[u][lg]] >= d[v]) u = par[u][lg];
  if (u == v) return u;
  for (int lg = 20; lg >= 0; --lg)
    if (par[u][lg] != par[v][lg]) {
      u = par[u][lg];
      v = par[v][lg];
    }
  return par[u][0];
}
int go(int u, int p, int w) {
  if (u != nxt[u]) return u = go(nxt[u], p, w);
  if (d[u] <= d[p]) return u;
  rz[u] = w;
  return nxt[u] = go(par[u][0], p, w);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k >> m;
  for (int i = 1; i <= k; ++i) cin >> g[i].first >> g[i].second;
  for (int i = 1; i <= m; ++i) {
    cin >> f[i].first >> f[i].second;
    cin >> w[i];
  }
  memset(lab, -1, sizeof lab);
  for (int i = 1; i <= k; ++i) {
    Union(g[i].first, g[i].second);
    e[g[i].first].push_back(g[i].second);
    e[g[i].second].push_back(g[i].first);
  }
  for (int i = 1; i <= m; ++i)
    if (choose[i] = Union(f[i].first, f[i].second)) {
      e[f[i].first].push_back(f[i].second);
      e[f[i].second].push_back(f[i].first);
    }
  dfs(1);
  for (int lg = 1; lg < Log; ++lg)
    for (int i = 1; i <= n; ++i) par[i][lg] = par[par[i][lg - 1]][lg - 1];
  d[0] = -1;
  for (int i = 1; i <= n; ++i) rz[i] = INF, nxt[i] = i;
  for (int i = 1; i <= m; ++i) {
    int u = f[i].first, v = f[i].second, p = lca(u, v);
    go(u, p, w[i]);
    go(v, p, w[i]);
  }
  long long result = 0;
  for (int i = 2; i <= n; ++i) {
    result += rz[i];
    if (nxt[i] == i) {
      cout << -1;
      return 0;
    }
  }
  for (int i = 1; i <= m; ++i) result -= choose[i] * w[i];
  cout << result;
}
