#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff, SINF = 0x3f3f3f3f;
const double PI = 3.141592653589793;
const long long LINF = 0x7fffffffffffffffLL, SLINF = 0x3f3f3f3f3f3f3f3fLL;
int _v, _f, _c;
long long _l;
void read() {
  _c = getchar(), _v = _f = 0;
  while (_c < '0' || _c > '9') {
    if (_c == -1) {
      _f = -1;
      return;
    } else if (_c == '-') {
      _f = 1;
    }
    _c = getchar();
  }
  while (_c <= '9' && _c >= '0') {
    _v = (_v << 3) + (_v << 1) + (_c ^ 48);
    _c = getchar();
  }
  if (_f) {
    _v = -_v;
  }
}
void read_ll() {
  _c = getchar(), _l = _f = 0;
  while (_c < '0' || _c > '9') {
    if (_c == -1) {
      _f = -1;
      return;
    } else if (_c == '-') {
      _f = 1;
    }
    _c = getchar();
  }
  while (_c <= '9' && _c >= '0') {
    _l = (_l << 3) + (_l << 1) + (_c ^ 48);
    _c = getchar();
  }
  if (_f) {
    _l = -_l;
  }
}
const int MAXN = 500005, MAXM = 100005, MAXK = 100005, MOD = 1e9 + 7;
const double EPS = 1e-8;
int num, eds, qus;
struct Edge {
  int t, n, l;
} edge[MAXN * 2];
int head[MAXN], en;
void add_e(int f, int t, int l = 0) {
  edge[en].t = t, edge[en].n = head[f], edge[en].l = l, head[f] = en++;
}
int fa[MAXN];
void init() {
  for (int i = 0; i < num; i++) {
    fa[i] = i;
  }
}
int get(int i) { return i == fa[i] ? i : (fa[i] = get(fa[i])); }
void conn(int i, int j) { fa[get(i)] = get(j); }
int dep[MAXN], p[MAXN][20], mn[MAXN][20], comp[MAXN];
void dfs(int cur = 0, int last = -1) {
  for (int i = head[cur]; ~i; i = edge[i].n) {
    if (edge[i].t != last) {
      comp[edge[i].t] = edge[i].l;
      dep[edge[i].t] = dep[cur] + 1;
      p[edge[i].t][0] = cur;
      for (int j = 1; j < 20; j++) {
        p[edge[i].t][j] = p[p[edge[i].t][j - 1]][j - 1];
      }
      dfs(edge[i].t, cur);
    }
  }
}
void modify(int a, int b, int v) {
  if (dep[a] < dep[b]) {
    swap(a, b);
  }
  for (int j = 19; ~j; j--) {
    if (dep[a] >= (1 << j) && dep[p[a][j]] >= dep[b]) {
      mn[a][j] = min(mn[a][j], v);
      a = p[a][j];
    }
  }
  if (a == b) {
    return;
  }
  for (int j = 19; ~j; j--) {
    if (p[a][j] != p[b][j]) {
      mn[a][j] = min(mn[a][j], v);
      mn[b][j] = min(mn[b][j], v);
      a = p[a][j], b = p[b][j];
    }
  }
  mn[a][0] = min(mn[a][0], v);
  mn[b][0] = min(mn[b][0], v);
  return;
}
void finalize() {
  for (int j = 19; j; j--) {
    for (int i = 0; i < num; i++) {
      if (dep[i] >= (1 << j)) {
        mn[i][j - 1] = min(mn[i][j - 1], mn[i][j]);
        mn[p[i][j - 1]][j - 1] = min(mn[p[i][j - 1]][j - 1], mn[i][j]);
      }
    }
  }
}
int qf[MAXN], qt[MAXN], ql[MAXN], sel[MAXN];
int main() {
  memset(head, -1, sizeof(head));
  num = (read(), _v), eds = (read(), _v), qus = (read(), _v);
  init();
  for (int i = 0; i < eds; i++) {
    int f = (read(), _v) - 1, t = (read(), _v) - 1;
    add_e(f, t), add_e(t, f);
    conn(f, t);
  }
  for (int i = 0; i < qus; i++) {
    qf[i] = (read(), _v) - 1, qt[i] = (read(), _v) - 1, ql[i] = (read(), _v);
    if (get(qf[i]) != get(qt[i])) {
      add_e(qf[i], qt[i], 1);
      add_e(qt[i], qf[i], 1);
      conn(qf[i], qt[i]);
      sel[i] = true;
    }
  }
  dfs();
  memset(mn, 0x3f, sizeof(mn));
  for (int i = 0; i < qus; i++) {
    if (!sel[i]) {
      modify(qf[i], qt[i], ql[i]);
    }
  }
  finalize();
  long long ans = 0;
  for (int i = 1; i < num; i++) {
    if (!comp[i]) {
      if (mn[i][0] >= SINF) {
        ans = SLINF;
        break;
      }
      ans += mn[i][0];
    }
  }
  printf("%lld\n", ans >= SLINF ? -1 : ans);
  return 0;
}
