#include <bits/stdc++.h>
using namespace std;
int nxt[500005 * 2], mrk[500005 * 2], nxt2[500005 * 2];
set<int> gl, ins[500005 * 2], del[500005 * 2];
vector<pair<int, int> > graph[500005 * 2];
vector<pair<int, pair<int, int> > > ed;
long long ans = 0;
int Find(int x) {
  if (x != nxt[x]) nxt[x] = Find(nxt[x]);
  return nxt[x];
}
void Union(int x, int y) {
  int a = Find(x);
  int b = Find(y);
  nxt[a] = b;
}
int dp[500005 * 2][25], par[500005 * 2], lev[500005 * 2];
void dfs0(int u, int p, int level) {
  lev[u] = level;
  for (int j = 0; j < graph[u].size(); j++) {
    int v = graph[u][j].first;
    int fl = graph[u][j].second;
    if (v != p) {
      if (fl)
        nxt2[v] = v;
      else
        nxt2[v] = u;
      dfs0(v, u, level + 1);
      par[v] = u;
    }
  }
}
void create(int n) {
  int i, j;
  for (i = 1; i <= n; i++)
    for (j = 0; j <= 22; j++) dp[i][j] = -1;
  for (i = 1; i <= n; i++) {
    dp[i][0] = par[i];
  }
  for (j = 1; j <= 22; j++)
    for (i = 1; i <= n; i++) {
      if (dp[i][j - 1] != -1) {
        dp[i][j] = dp[dp[i][j - 1]][j - 1];
      }
    }
}
int cal(int u, int v) {
  if (lev[u] < lev[v]) swap(u, v);
  for (int j = 21; j >= 0; j--) {
    if (lev[u] - (1 << j) >= lev[v]) {
      u = dp[u][j];
    }
  }
  if (u == v) return u;
  for (int i = 21; i >= 0; i--) {
    if (dp[u][i] != -1 && dp[u][i] != dp[v][i]) {
      u = dp[u][i];
      v = dp[v][i];
    }
  }
  return par[u];
}
int Find2(int x) {
  if (x != nxt2[x]) nxt2[x] = Find2(nxt2[x]);
  return nxt2[x];
}
int ct = 0;
void f(int x, int y, int w) {
  x = Find2(x);
  while (x != 1 && lev[x] > lev[y]) {
    ans += (long long)w;
    nxt2[x] = par[x];
    x = Find2(x);
    ct++;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, m, i;
  cin >> n >> k >> m;
  for (i = 1; i <= n; i++) nxt[i] = nxt2[i] = i;
  for (i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    ed.push_back(pair<int, pair<int, int> >(0, pair<int, int>(x, y)));
  }
  for (i = 1; i <= m; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    ed.push_back(pair<int, pair<int, int> >(w, pair<int, int>(x, y)));
  }
  sort(ed.begin(), ed.end());
  int ct2 = 0;
  for (i = 0; i < ed.size(); i++) {
    int u = ed[i].second.first;
    int v = ed[i].second.second;
    int w = ed[i].first;
    if (Find(u) != Find(v)) {
      int fl;
      if (i < k) {
        fl = 1;
      } else {
        fl = 0;
        ct2++;
      }
      graph[u].push_back(pair<int, int>(v, fl));
      graph[v].push_back(pair<int, int>(u, fl));
      Union(u, v);
      mrk[i] = 1;
    }
  }
  dfs0(1, -1, 0);
  create(n);
  for (i = k; i < ed.size(); i++) {
    if (mrk[i] == 0) {
      int u = ed[i].second.first;
      int v = ed[i].second.second;
      int w = ed[i].first;
      int uv = cal(u, v);
      f(u, uv, w);
      f(v, uv, w);
    }
  }
  for (i = 2; i <= n; i++) {
    if (nxt2[i] == i) {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
  return 0;
}
