#include <bits/stdc++.h>
using namespace std;
int depth[500010];
struct UnionFind {
  vector<int> v, t;
  UnionFind(int n) : v(n, -1), t(n, -1) {
    for (long long i = (long long)(0); i < (long long)(n); i++) t[i] = i;
  }
  void init() {
    for (int i = 0; i < (int)v.size(); i++) v[i] = -1;
  }
  int find(int x) { return v[x] < 0 ? x : find(v[x]); }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y];
    v[y] = x;
    if (depth[t[y]] < depth[t[x]]) t[x] = t[y];
    return true;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
};
int N, M, K;
vector<int> G[500010];
int parent[20][500010];
void dfs(int v, int p, int d) {
  parent[0][v] = p;
  depth[v] = d;
  for (int i = 0; i < (int)G[v].size(); i++) {
    if (G[v][i] != p) dfs(G[v][i], v, d + 1);
  }
}
int lca(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int k = 0; k < 20; k++) {
    if ((depth[v] - depth[u]) >> k & 1) {
      v = parent[k][v];
      if (v == -1) return -1;
    }
  }
  if (u == v) return u;
  for (int k = 20 - 1; k >= 0; k--) {
    if (parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      if (u == -1) return -1;
      v = parent[k][v];
      if (v == -1) return -1;
    }
  }
  if (parent[0][u] != parent[0][v])
    return -1;
  else
    return parent[0][u];
}
int u[1000010], v[1000010];
int w[500010];
int main() {
  scanf("%d%d%d", &N, &K, &M);
  UnionFind preuf(N);
  for (long long i = (long long)(0); i < (long long)(K); i++) {
    scanf("%d%d", &u[i + M], &v[i + M]);
    u[i + M]--;
    v[i + M]--;
    G[u[i + M]].push_back(v[i + M]);
    G[v[i + M]].push_back(u[i + M]);
    preuf.unite(u[i + M], v[i + M]);
  }
  long long res = 0;
  for (long long i = (long long)(0); i < (long long)(M); i++) {
    scanf("%d%d%lld", &u[i], &v[i], &w[i]);
    u[i]--;
    v[i]--;
    if (!preuf.same(u[i], v[i])) {
      G[u[i]].push_back(v[i]);
      G[v[i]].push_back(u[i]);
      preuf.unite(u[i], v[i]);
      res -= w[i];
    }
  }
  memset(depth, -1, sizeof(depth));
  for (long long i = (long long)(0); i < (long long)(N); i++) {
    if (depth[i] == -1) dfs(i, -1, 0);
  }
  for (int k = 0; k + 1 < 20; k++) {
    for (int a = 0; a < N; a++) {
      if (parent[k][a] < 0)
        parent[k + 1][a] = -1;
      else
        parent[k + 1][a] = parent[k][parent[k][a]];
    }
  }
  UnionFind uf(N);
  for (long long i = (long long)(0); i < (long long)(M); i++) {
    if (uf.same(u[i], v[i])) continue;
    int par = lca(u[i], v[i]);
    if (par == -1) {
      uf.unite(u[i], v[i]);
      continue;
    } else {
      int crtu = u[i], crtv = v[i];
      crtu = uf.t[uf.find(crtu)];
      crtv = uf.t[uf.find(crtv)];
      while (depth[crtu] > depth[par]) {
        uf.unite(crtu, parent[0][crtu]);
        res += (long long)w[i];
        crtu = parent[0][crtu];
        crtu = uf.t[uf.find(crtu)];
      }
      while (depth[crtv] > depth[par]) {
        uf.unite(crtv, parent[0][crtv]);
        res += (long long)w[i];
        crtv = parent[0][crtv];
        crtv = uf.t[uf.find(crtv)];
      }
    }
  }
  for (long long i = (long long)(0); i < (long long)(K); i++) {
    if (!uf.same(u[i + M], v[i + M])) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << res << endl;
  return 0;
}
