#include <bits/stdc++.h>
using namespace std;
struct arr {
  int x, y, z;
} a[1100000];
struct node {
  int x, y;
  node(int a, int b) {
    x = a;
    y = b;
  }
};
int f[1100000], g[1100000], fa[1100000], dep[1100000], b[1100000];
vector<node> c[1100000];
int find(int k) {
  if (fa[k] != k) fa[k] = find(fa[k]);
  return fa[k];
}
void dfs(int u) {
  dep[u] = dep[f[u]] + 1;
  for (int i = 0; i <= (int)c[u].size() - 1; i++) {
    int v = c[u][i].x;
    if (v != f[u]) {
      f[v] = u;
      g[v] = c[u][i].y;
      dfs(v);
    }
  }
}
int main() {
  int n, k, m;
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    c[x].push_back(node(y, 0));
    c[y].push_back(node(x, 0));
    fa[find(x)] = find(y);
  }
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].z);
  for (int i = 1; i <= m; i++) {
    int t1 = find(a[i].x);
    int t2 = find(a[i].y);
    if (t1 != t2) {
      fa[t1] = t2;
      c[a[i].x].push_back(node(a[i].y, a[i].z));
      c[a[i].y].push_back(node(a[i].x, a[i].z));
      b[i] = 1;
    }
  }
  f[1] = 1;
  dfs(1);
  for (int i = 1; i <= n; i++) fa[i] = i;
  long long ans = 0;
  for (int i = 1; i <= m; i++)
    if (!b[i]) {
      int x = find(a[i].x), y = find(a[i].y);
      while (x != y) {
        if (dep[x] < dep[y]) swap(x, y);
        if (!g[x]) {
          ans += a[i].z;
          g[x] = a[i].z;
        }
        fa[x] = find(f[x]);
        x = find(x);
      }
    }
  for (int i = 2; i <= n; i++)
    if (!g[i]) {
      printf("-1\n");
      return 0;
    }
  printf("%lld\n", ans);
  return 0;
}
