#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int N = 5e5 + 2, INF = 1e9 + 7;
int n, K, m, rt[N], dep[N], head[N], pos[N], rk[N], lz[N << 2], sz[N], nhld,
    val[N], par[N];
vector<pair<int, int> > g[N];
pair<pair<int, int>, int> edge[N];
int frt(int i) { return rt[i] == i ? i : rt[i] = frt(rt[i]); }
void dfs(int u, int p) {
  sz[u] = 1;
  dep[u] = dep[p] + 1;
  par[u] = p;
  for (auto &v : g[u])
    if (v.first != p) dfs(v.first, u), sz[u] += sz[v.first];
}
void hld(int u, int p, int h) {
  head[u] = h;
  pos[u] = ++nhld;
  int mx = 0, big = -1;
  for (auto &v : g[u])
    if (v.first != p && mx < sz[v.first]) mx = sz[v.first], big = v.first;
  if (big != -1) hld(big, u, h);
  for (auto &v : g[u])
    if (v.first != p && v.first != big) hld(v.first, u, v.first);
}
void dolz(int id, int l, int r) {
  if (l == r || lz[id] == INF) return;
  lz[id << 1] = min(lz[id << 1], lz[id]);
  lz[(id << 1) | 1] = min(lz[(id << 1) | 1], lz[id]);
  lz[id] = INF;
}
void update(int id, int l, int r, int L, int R, int v) {
  dolz(id, l, r);
  if (l > R || r < L) return;
  if (L <= l && r <= R) {
    lz[id] = min(lz[id], v);
    dolz(id, l, r);
    return;
  }
  int mi = (l + r) >> 1;
  update(id << 1, l, mi, L, R, v);
  update((id << 1) | 1, mi + 1, r, L, R, v);
}
void push(int id, int l, int r) {
  if (l == r) {
    val[l] = lz[id];
    return;
  }
  dolz(id, l, r);
  int mi = (l + r) >> 1;
  push(id << 1, l, mi);
  push((id << 1) | 1, mi + 1, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> K >> m;
  for (int i = (1); i <= (n); ++i) rt[i] = i;
  for (int i = (1); i <= (K); ++i) {
    int u, v;
    cin >> u >> v;
    g[u].emplace_back(v, 0);
    g[v].emplace_back(u, 0);
    u = frt(u), v = frt(v);
    if (rk[u] == rk[v]) rk[u]++;
    if (rk[u] < rk[v]) swap(u, v);
    rt[v] = u;
  }
  for (int i = (1); i <= (m); ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    edge[i] = {{u, v}, w};
    u = frt(u), v = frt(v);
    if (u != v) {
      if (rk[u] == rk[v]) rk[u]++;
      if (rk[u] < rk[v]) swap(u, v);
      rt[v] = u;
      g[edge[i].first.first].emplace_back(edge[i].first.second, 1);
      g[edge[i].first.second].emplace_back(edge[i].first.first, 1);
      edge[i] = {{-1, -1}, -1};
    }
  }
  dfs(1, 0);
  hld(1, 0, 1);
  fill(lz, lz + (n << 2), INF);
  for (int i = (1); i <= (m); ++i)
    if (edge[i].first.first != -1) {
      int u = edge[i].first.first, v = edge[i].first.second;
      for (; head[u] != head[v]; u = par[head[u]]) {
        if (dep[head[u]] < dep[head[v]]) swap(u, v);
        update(1, 1, n, pos[head[u]], pos[u], edge[i].second);
      }
      if (dep[u] < dep[v]) swap(u, v);
      update(1, 1, n, pos[v] + 1, pos[u], edge[i].second);
    }
  push(1, 1, n);
  ll ans = 0;
  for (int u = (1); u <= (n); ++u) {
    for (auto &v : g[u])
      if (v.first != par[u] && v.second == 0) {
        if (val[pos[v.first]] == INF) {
          cout << -1;
          return 0;
        }
        ans += val[pos[v.first]];
      }
  }
  cout << ans;
  return 0;
}
