#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
struct edge {
  int x, y, w;
} e[500010];
int n, k, m, fa[500010][25], f[500010][25], d[500010], par[500010];
int cnt, head[500010], to[1000010], nxt[1000010];
void add(int x, int y) {
  cnt++;
  to[cnt] = y;
  nxt[cnt] = head[x];
  head[x] = cnt;
}
int find(int x) {
  if (par[x] != x) {
    par[x] = find(par[x]);
  }
  return par[x];
}
void Union(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) {
    return;
  }
  par[x] = y;
}
void dfs(int x) {
  f[x][0] = inf;
  for (int i = head[x]; i; i = nxt[i]) {
    int y = to[i];
    if (y == fa[x][0]) {
      continue;
    }
    fa[y][0] = x;
    d[y] = d[x] + 1;
    dfs(y);
  }
}
void bz() {
  for (int i = 1; i <= 20; i++) {
    for (int j = 1; j <= n; j++) {
      fa[j][i] = fa[fa[j][i - 1]][i - 1];
      f[j][i] = inf;
    }
  }
}
void work(int x, int y, int w) {
  if (d[x] < d[y]) {
    swap(x, y);
  }
  int dis = d[x] - d[y];
  for (int i = 20; i >= 0; i--) {
    if (dis & (1 << i)) {
      f[x][i] = min(f[x][i], w);
      x = fa[x][i];
    }
  }
  if (x == y) {
    return;
  }
  for (int i = 20; i >= 0; i--) {
    if (fa[x][i] != fa[y][i]) {
      f[x][i] = min(f[x][i], w);
      f[y][i] = min(f[y][i], w);
      x = fa[x][i];
      y = fa[y][i];
    }
  }
  f[x][0] = min(f[x][0], w);
  f[y][0] = min(f[y][0], w);
}
void work() {
  for (int i = 20; i; i--) {
    for (int j = 1; j <= n; j++) {
      f[j][i - 1] = min(f[j][i - 1], f[j][i]);
      f[fa[j][i - 1]][i - 1] = min(f[fa[j][i - 1]][i - 1], f[j][i]);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= n; i++) {
    par[i] = i;
  }
  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
    Union(x, y);
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].w);
  }
  long long ans = 0;
  for (int i = 0; i < m; i++) {
    int x = e[i].x;
    int y = e[i].y;
    if (find(x) != find(y)) {
      add(x, y);
      add(y, x);
      Union(x, y);
      ans -= e[i].w;
    }
  }
  d[1] = 1;
  dfs(1);
  bz();
  for (int i = 0; i < m; i++) {
    work(e[i].x, e[i].y, e[i].w);
  }
  work();
  for (int i = 2; i <= n; i++) {
    if (f[i][0] == inf) {
      puts("-1");
      return 0;
    }
    ans += f[i][0];
  }
  cout << ans << endl;
  return 0;
}
