#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
inline void cmin(int &x, int y) {
  if (y < x) x = y;
}
const int N = 5e5 + 233;
struct ed {
  int x, y, w, mk;
} e[N], g[N];
bool cmp(ed A, ed B) { return A.w < B.w; }
struct ED {
  int v, id;
};
vector<ED> G[N];
void adde(int x, int y, int id) {
  G[x].push_back((ED){y, id}), G[y].push_back((ED){x, id});
}
int fa[N], n, m, K, p[N][20], tg[N][20], dep[N], pos[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void update(int x, int y, int w) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int j = 19; j >= 0; --j)
    if (dep[x] - (1 << j) >= dep[y]) cmin(tg[x][j], w), x = p[x][j];
  if (x == y) return;
  for (int j = 19; j >= 0; --j)
    if (p[x][j] != p[y][j])
      cmin(tg[x][j], w), cmin(tg[y][j], w), x = p[x][j], y = p[y][j];
  cmin(tg[x][0], w), cmin(tg[y][0], w);
}
void dfs(int u, int last) {
  dep[u] = dep[last] + 1, p[u][0] = last;
  for (int j = 1; j <= 19; ++j) p[u][j] = p[p[u][j - 1]][j - 1];
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i].v;
    if (v == last) continue;
    pos[v] = G[u][i].id;
    dfs(v, u);
  }
}
int main() {
  read(n), read(K), read(m);
  for (int i = 1; i <= K; ++i) read(g[i].x), read(g[i].y);
  for (int i = 1; i <= m; ++i) read(e[i].x), read(e[i].y), read(e[i].w);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  sort(e + 1, e + m + 1, cmp);
  long long ans = 0;
  int flg = 0;
  for (int i = 1; i <= K; ++i)
    fa[find(g[i].x)] = find(g[i].y), adde(g[i].x, g[i].y, i);
  for (int i = 1; i <= m; ++i)
    if (find(e[i].x) != find(e[i].y))
      fa[find(e[i].x)] = find(e[i].y), adde(e[i].x, e[i].y, 0), e[i].mk = 1;
  dfs(1, 0);
  memset(tg, 0x3f, sizeof(tg));
  for (int i = 1; i <= m; ++i)
    if (!e[i].mk) update(e[i].x, e[i].y, e[i].w);
  for (int j = 19; j > 0; --j)
    for (int i = 1; i <= n; ++i)
      cmin(tg[i][j - 1], tg[i][j]), cmin(tg[p[i][j - 1]][j - 1], tg[i][j]);
  for (int i = 2; i <= n; ++i)
    if (pos[i]) {
      ans += tg[i][0];
      if (tg[i][0] > 1e9) flg = 1;
    }
  if (!flg)
    printf("%lld", ans);
  else
    printf("-1");
  return 0;
}
