#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const long long maxn = 5e5 + 10, maxm = 5e2 + 10, lg = 18, mod = 1e9 + 7,
                inf = 1e18;
long long n, k, m, ans, par[maxn];
vector<long long> g[maxn];
map<pair<long long, long long>, bool> dd;
set<pair<long long, long long>> ss[maxn];
long long gpar(long long v) {
  return (par[v] == v ? v : par[v] = gpar(par[v]));
}
void drg(long long v, long long u) { par[gpar(v)] = gpar(u); }
void mrg(set<pair<long long, long long>> &m1,
         set<pair<long long, long long>> &m2) {
  if ((long long)(m1.size()) < (long long)(m2.size())) m1.swap(m2);
  for (auto x : m2) {
    auto it = m1.find(x);
    if (it != m1.end())
      m1.erase(it);
    else
      m1.insert(x);
  }
}
void dfs(long long v = 1, long long p = 0) {
  for (auto u : g[v])
    if (u != p) {
      dfs(u, v);
      if (dd.count({v, u}) == 0) {
        if (ss[u].empty()) {
          cout << -1;
          exit(0);
        }
        ans += ss[u].begin()->first;
      }
      mrg(ss[v], ss[u]);
    }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  iota(par, par + maxn, 0);
  cin >> n >> k >> m;
  while (k--) {
    long long v, u;
    cin >> v >> u;
    g[v].push_back(u), g[u].push_back(v);
    drg(v, u);
  }
  vector<pair<long long, pair<long long, long long>>> E;
  while (m--) {
    long long v, u, w;
    cin >> v >> u >> w;
    E.push_back({w, {v, u}});
  }
  sort(E.begin(), E.end());
  long long tt = 0;
  for (auto e : E) {
    long long v = e.second.first, u = e.second.second, w = e.first;
    if (gpar(v) == gpar(u)) {
      ss[v].insert({w, tt});
      ss[u].insert({w, tt});
      tt++;
      continue;
    }
    dd[{v, u}] = dd[{u, v}] = 1;
    g[v].push_back(u), g[u].push_back(v);
    drg(v, u);
  }
  dfs();
  cout << ans;
  return 0;
}
