#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
const long long INF = 100000000;
const long long MOD = 1000000007;
struct UF {
  int par[500000];
  int rank[500000];
  int si[500000];
  void init(int n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      rank[i] = 0;
      si[i] = 1;
    }
  }
  int find(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[x] = y;
      si[y] += si[x];
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
      si[x] += si[y];
    }
  }
  bool same(int x, int y) { return find(x) == find(y); }
} uf;
struct edge {
  int id;
  int a, b;
  int w;
  bool operator<(const edge& right) const { return w < right.w; }
} ek[500000], em[500000];
int n, k, m;
vector<pair<long long, long long> > e[500000];
bool used[500000];
int par[22][500000];
int parw[500000];
int dep[500000];
int jump[500000];
bool done[500000];
void dfs(int v, int d = 0) {
  dep[v] = d;
  for (int i = 0; i < e[v].size(); i++) {
    if (e[v][i].first == par[0][v]) continue;
    par[0][e[v][i].first] = v;
    parw[e[v][i].first] = e[v][i].second;
    dfs(e[v][i].first, d + 1);
  }
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 0; i < k; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    ek[i].id = 0;
    ek[i].a = a;
    ek[i].b = b;
    e[a].push_back(pair<long long, long long>(b, MOD));
    e[b].push_back(pair<long long, long long>(a, MOD));
  }
  uf.init(n);
  for (int i = 0; i < m; i++) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    a--;
    b--;
    em[i].id = 0;
    em[i].a = a;
    em[i].b = b;
    em[i].w = w;
    uf.unite(a, b);
  }
  uf.init(n);
  for (int i = 0; i < k; i++) {
    uf.unite(ek[i].a, ek[i].b);
  }
  sort(em, em + m);
  for (int i = 0; i < m; i++) {
    if (uf.same(em[i].a, em[i].b)) continue;
    uf.unite(em[i].a, em[i].b);
    used[i] = true;
    e[em[i].a].push_back(pair<long long, long long>(em[i].b, -1));
    e[em[i].b].push_back(pair<long long, long long>(em[i].a, -1));
  }
  par[0][0] = 0;
  dfs(0);
  for (int i = 0; i + 1 < 22; i++) {
    for (int j = 0; j < n; j++) {
      par[i + 1][j] = par[i][par[i][j]];
    }
  }
  done[0] = true;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    jump[i] = par[0][i];
  }
  for (int i = 0; i < m; i++) {
    if (used[i]) continue;
    int a = em[i].a, b = em[i].b;
    if (dep[a] > dep[b]) swap(a, b);
    int tmpa = a, tmpb = b;
    for (int j = 22 - 1; j >= 0; j--) {
      if (dep[tmpb] - (1 << j) >= dep[tmpa]) {
        tmpb = par[j][tmpb];
      }
    }
    for (int j = 22 - 1; j >= 0; j--) {
      if (par[j][tmpa] != par[j][tmpb]) {
        tmpa = par[j][tmpa];
        tmpb = par[j][tmpb];
      }
    }
    int lca = tmpa != tmpb ? par[0][tmpa] : tmpa;
    while (dep[b] > dep[lca]) {
      parw[b] = min(parw[b], em[i].w);
      int hoge = b;
      b = jump[b];
      jump[hoge] = lca;
    }
    while (dep[a] > dep[lca]) {
      parw[a] = min(parw[a], em[i].w);
      int hoge = a;
      a = jump[a];
      jump[hoge] = lca;
    }
  }
  for (int i = 0; i < n; i++) {
    if (par[0][i] == i) continue;
    if (parw[i] == -1) continue;
    if (parw[i] == MOD) {
      puts("-1");
      return 0;
    }
    ans += parw[i];
  }
  printf("%lld\n", ans);
}
