#include <bits/stdc++.h>
using namespace std;
const int mx = 5e5 + 10;
struct HLD {
  vector<int> last, idx, cnt, par;
  vector<vector<int> > adj;
  int n, rt, c = 0;
  HLD() {}
  HLD(int _n, int _rt) {
    n = _n;
    rt = _rt;
    last.resize(n + 1);
    idx.resize(n + 1);
    cnt.resize(n + 1);
    par.resize(n + 1);
    adj.resize(n + 1);
  }
  void add_edge(int x, int y) {
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  void count(int h, int p) {
    for (int it : adj[h])
      if (it ^ p) count(it, h), cnt[h] += cnt[it];
    cnt[h]++;
  }
  void build(int h, int p) {
    int t = 0;
    for (int it : adj[h])
      if (it ^ p && cnt[t] < cnt[it]) t = it;
    for (int it : adj[h])
      if (it ^ p && it ^ t) build(it, h);
    if (!last[h]) last[h] = h;
    if (t) last[t] = last[h], build(t, h);
    par[h] = p;
    idx[h] = ++c;
  }
  void generate() {
    count(rt, -1);
    build(rt, -1);
  }
  vector<pair<int, int> > lca(int x, int y) {
    vector<pair<int, int> > ret;
    while (last[x] ^ last[y]) {
      if (cnt[last[x]] > cnt[last[y]]) swap(x, y);
      ret.push_back({idx[x], idx[last[x]]});
      x = par[last[x]];
    }
    if (cnt[x] ^ cnt[y]) {
      if (cnt[x] > cnt[y]) swap(x, y);
      ret.push_back({idx[x], idx[y] - 1});
    }
    return ret;
  }
};
int tree[mx * 4];
void update(int h, int l, int r, int gl, int gr, int x) {
  if (r < gl || gr < l) return;
  if (gl <= l && r <= gr) {
    tree[h] = min(tree[h], x);
    return;
  }
  int mid = l + r >> 1;
  update(h * 2 + 1, l, mid, gl, gr, x);
  update(h * 2 + 2, mid + 1, r, gl, gr, x);
}
const int in = 2e9;
int query(int h, int l, int r, int g) {
  if (r < g || g < l) return in;
  if (l == r) return tree[h];
  int mid = l + r >> 1;
  return min(
      {tree[h], query(h * 2 + 1, l, mid, g), query(h * 2 + 2, mid + 1, r, g)});
}
struct st {
  int x, y, z;
} e[mx];
int n, m, q, u[mx], from[mx], to[mx], p[mx];
int par(int x) { return x ^ p[x] ? p[x] = par(p[x]) : x; }
int vis[mx];
HLD *hld;
int main() {
  scanf("%d%d%d", &n, &q, &m);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", from + i, to + i);
  }
  for (int i = 0; i < m; i++) scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].z);
  hld = new HLD(n, 1);
  for (int i = 1; i <= n; i++) p[i] = i;
  for (int i = 0; i < q; i++) {
    p[par(from[i])] = par(to[i]);
    hld->add_edge(from[i], to[i]);
  }
  long long res = 0;
  for (int i = 0; i < m; i++) {
    if (par(e[i].x) != par(e[i].y)) {
      p[par(e[i].x)] = par(e[i].y);
      hld->add_edge(e[i].x, e[i].y);
    }
  }
  fill(&tree[0], &tree[mx * 4], in);
  hld->generate();
  for (int i = 0; i < m; i++) {
    vector<pair<int, int> > vp = hld->lca(e[i].x, e[i].y);
    for (auto &it : vp) {
      update(0, 1, n + 1, it.first, it.second, e[i].z);
    }
  }
  for (int i = 0; i < q; i++) {
    int ra = hld->idx[from[i]], rb = hld->idx[to[i]];
    if (ra > rb) swap(ra, rb);
    int tmp = query(0, 1, n + 1, ra);
    if (tmp == in) {
      puts("-1");
      return 0;
    }
    res += tmp;
  }
  printf("%lld", res);
  return 0;
}
