#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
const int maxn = 5e5 + 5;
const int logn = 20;
int n, k, m;
pair<int, int> edges[maxn];
pair<int, int> medges[maxn];
int w[maxn];
vector<pair<int, int> > adj[maxn];
int dj[maxn];
int from[maxn];
int lev[maxn];
int par[logn][maxn];
int mn[logn][maxn];
int find(int u) { return dj[u] == u ? dj[u] : dj[u] = find(dj[u]); }
int join(int u, int v) {
  int p = find(u);
  int q = find(v);
  if (p != q) {
    dj[p] = q;
    return 1;
  }
  return 0;
}
vector<int> ver;
void dfs(int u, int p) {
  for (int i = (1); i < (logn); ++i) par[i][u] = par[i - 1][par[i - 1][u]];
  for (pair<int, int> e : adj[u]) {
    int v = e.first;
    int ix = e.second;
    if (v != p) {
      from[v] = ix;
      lev[v] = lev[u] + 1;
      par[0][v] = u;
      dfs(v, u);
    }
  }
  ver.push_back(u);
}
int lca(int u, int v) {
  if (lev[u] < lev[v]) swap(u, v);
  for (int i = (logn)-1; i >= (0); --i) {
    if (lev[par[i][u]] >= lev[v]) {
      u = par[i][u];
    }
  }
  if (u == v) return u;
  for (int i = (logn)-1; i >= (0); --i) {
    if (par[i][u] != par[i][v]) {
      u = par[i][u];
      v = par[i][v];
    }
  }
  return par[0][u];
}
void chemthan() {
  cin >> n >> k >> m;
  for (int i = (0); i < (k); ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    edges[i] = make_pair(u, v);
  }
  for (int i = (0); i < (m); ++i) {
    int u, v;
    cin >> u >> v >> w[i];
    u--, v--;
    medges[i] = make_pair(u, v);
  }
  for (int i = (0); i < (n); ++i) dj[i] = i;
  for (int i = (0); i < (k); ++i) {
    int u = edges[i].first;
    int v = edges[i].second;
    adj[u].push_back(make_pair(v, i));
    adj[v].push_back(make_pair(u, i));
    join(u, v);
  }
  static int used[maxn];
  for (int i = (0); i < (m); ++i) {
    int u = medges[i].first;
    int v = medges[i].second;
    if (join(u, v)) {
      adj[u].push_back(make_pair(v, k + i));
      adj[v].push_back(make_pair(u, k + i));
      used[i] = 1;
    }
  }
  dfs(0, -1);
  for (int i = (0); i < (logn); ++i)
    for (int u = (0); u < (n); ++u) mn[i][u] = INF;
  for (int i = (0); i < (m); ++i)
    if (!used[i]) {
      int u = medges[i].first;
      int v = medges[i].second;
      int a = lca(u, v);
      for (int t : {u, v}) {
        for (int j = (logn)-1; j >= (0); --j)
          if (t != a) {
            if (lev[par[j][t]] >= lev[a]) {
              chkmin(mn[j][t], w[i]);
              t = par[j][t];
            }
          }
      }
    }
  static int res[maxn];
  for (int u : ver) {
    for (int i = (logn)-1; i >= (1); --i) {
      chkmin(mn[i - 1][u], mn[i][u]);
      chkmin(mn[i - 1][par[i - 1][u]], mn[i][u]);
    }
    if (u) {
      int ix = from[u];
      if (ix < k) {
        res[ix] = mn[0][u];
      }
    }
  }
  for (int i = (0); i < (k); ++i)
    if (res[i] == INF) {
      cout << -1 << "\n";
      return;
    }
  cout << accumulate(res, res + k, 0LL) << "\n";
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  chemthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
