#include <bits/stdc++.h>
using namespace std;
const int N = 500000 + 10;
const int M = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
const int oo = 1000000000;
int n, k, m, prt[N], dp[19][N], D[N];
long long ans;
vector<int> ad[N], rem[N];
vector<pair<int, pair<int, int> > > E;
vector<pair<int, int> > g[N];
multiset<int> st[N];
void dfs(int u, int p) {
  int mx = -1, id, idc;
  for (int i = 0; i < g[u].size(); ++i) {
    int d = g[u][i].first, c = g[u][i].second;
    if (d == p) continue;
    dfs(d, u);
    if ((int)st[d].size() > mx) {
      mx = st[d].size();
      id = d;
      idc = c;
    }
  }
  if (mx == -1) {
    for (int x : ad[u]) st[u].insert(x);
    return;
  }
  if (!idc) {
    if (st[id].empty())
      ans = 2e18;
    else
      ans += *st[id].begin();
  }
  st[u].swap(st[id]);
  for (int i = 0; i < g[u].size(); ++i) {
    int d = g[u][i].first, c = g[u][i].second;
    if (d == p || d == id) continue;
    if (!c) {
      if (st[d].empty())
        ans = 2e18;
      else
        ans += *st[d].begin();
    }
    for (int x : st[d]) st[u].insert(x);
  }
  for (int x : ad[u]) st[u].insert(x);
  for (int x : rem[u]) {
    st[u].erase(st[u].find(x));
    st[u].erase(st[u].find(x));
  }
}
int get(int u) { return prt[u] == u ? u : prt[u] = get(prt[u]); }
void build(int u, int p) {
  dp[0][u] = p;
  for (int i = 1; i < 19; ++i) {
    if (dp[i - 1][u] + 1)
      dp[i][u] = dp[i - 1][dp[i - 1][u]];
    else
      dp[i][u] = -1;
  }
  for (int i = 0; i < g[u].size(); ++i) {
    int d = g[u][i].first;
    if (d == p) continue;
    D[d] = D[u] + 1;
    build(d, u);
  }
}
int LCA(int u, int v) {
  if (D[u] < D[v]) swap(u, v);
  int l = 0;
  while ((1 << l) <= D[u]) ++l;
  --l;
  for (int i = l; i >= 0; --i)
    if (D[u] - (1 << i) >= D[v]) u = dp[i][u];
  if (u == v) return u;
  for (int i = l; i >= 0; --i)
    if (dp[i][u] - dp[i][v]) u = dp[i][u], v = dp[i][v];
  return dp[0][u];
}
int main() {
  cin >> n >> k >> m;
  for (int i = 0; i < n; ++i) prt[i] = i;
  for (int a, b, i = 0; i < k; ++i) {
    scanf("%d%d", &a, &b);
    --a;
    --b;
    E.push_back({0, {a, b}});
  }
  for (int a, b, c, i = 0; i < m; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    --a;
    --b;
    E.push_back({c, {a, b}});
  }
  sort((E).begin(), (E).end());
  for (int i = 0; i < E.size(); ++i) {
    int c = E[i].first, u = E[i].second.first, v = E[i].second.second;
    if (get(u) == get(v)) continue;
    prt[get(u)] = get(v);
    g[u].push_back({v, c});
    g[v].push_back({u, c});
  }
  build(0, -1);
  for (int i = 0; i < E.size(); ++i) {
    if (!E[i].first) continue;
    int a = E[i].second.first, b = E[i].second.second, c = E[i].first;
    int lca = LCA(a, b);
    ad[a].push_back(c);
    ad[b].push_back(c);
    rem[lca].push_back(c);
  }
  dfs(0, -1);
  if (ans > 1e18) ans = -1;
  cout << ans << endl;
  return 0;
}
