#include <bits/stdc++.h>
using namespace std;
const int nmax = 5e5;
int n, k, m;
struct str {
  int x, y, cst;
} v[nmax + 1];
struct dsu {
  int grad[nmax + 1], tata[nmax + 1];
  void init(int z) {
    for (int i = 1; i <= z; ++i) {
      grad[i] = 1;
      tata[i] = i;
    }
  }
  inline int find_tata(int x) {
    if (x == tata[x]) return x;
    return tata[x] = find_tata(tata[x]);
  }
  bool unite(int x, int y) {
    x = find_tata(x);
    y = find_tata(y);
    if (x == y) return 0;
    if (grad[x] < grad[y]) swap(x, y);
    grad[x] += grad[y];
    tata[y] = x;
    return 1;
  }
} ds1, ds2;
bool viz[nmax + 1];
vector<pair<int, bool>> g[nmax + 1];
int h[nmax + 1], up[nmax + 1];
bool intra[nmax + 1];
bool fol[nmax + 1];
void citire() {
  fscanf(stdin, "%d%d%d", &n, &k, &m);
  ds1.init(n);
  for (int i = 1; i <= k; ++i) {
    int x, y;
    fscanf(stdin, "%d%d", &x, &y);
    ds1.unite(x, y);
    g[x].push_back({y, 1});
    g[y].push_back({x, 1});
  }
  for (int i = 1; i <= m; ++i) {
    fscanf(stdin, "%d%d%d", &v[i].x, &v[i].y, &v[i].cst);
    fol[i] = ds1.unite(v[i].x, v[i].y);
    if (fol[i]) {
      g[v[i].x].push_back({v[i].y, 0});
      g[v[i].y].push_back({v[i].x, 0});
    }
  }
}
void dfs(int nod) {
  viz[nod] = 1;
  for (auto i : g[nod]) {
    if (viz[i.first] == 0) {
      up[i.first] = nod;
      h[i.first] = h[nod] + 1;
      intra[i.first] = i.second;
      dfs(i.first);
    }
  }
}
int find_nxt(int x) {
  if (x != 1 && ds2.find_tata(x) == ds2.find_tata(up[x])) {
    return up[x] = find_nxt(up[x]);
  }
  return up[x];
}
int main() {
  citire();
  dfs(1);
  long long ans = 0;
  ds2.init(n);
  up[1] = 1;
  int cons = k;
  for (int i = 1; i <= m; ++i) {
    int x = v[i].x, y = v[i].y;
    if (fol[i] == 1) continue;
    x = ds2.find_tata(x);
    y = ds2.find_tata(y);
    while (x != y) {
      if (h[x] < h[y]) swap(x, y);
      ans += intra[x] * v[i].cst;
      cons -= intra[x];
      ds2.tata[x] = up[x];
      x = ds2.find_tata(x);
    }
  }
  if (cons) ans = -1;
  fprintf(stdout, "%I64d\n", ans);
  return 0;
}
