#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 1e18;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 5;
struct edge {
  int u, v, c, id;
  bool operator<(const edge &rhs) const {
    return (c < rhs.c) || (c == rhs.c && id < rhs.id);
  }
};
set<edge> s[MAXN];
bool used[MAXN];
int ex[MAXN];
int par[MAXN];
priority_queue<edge> pq;
vector<int> g[MAXN];
vector<int> mst[MAXN];
edge e[MAXN];
int n, k, m;
long long ans;
int find(int v) {
  if (par[v] == v) return v;
  return par[v] = find(par[v]);
}
void kruskall() {
  for (int i = 0; i < n; i++) par[i] = i;
  while (!pq.empty()) {
    int u = pq.top().u, v = pq.top().v, id = pq.top().id;
    pq.pop();
    if (find(u) != find(v)) {
      par[find(u)] = find(v);
      used[id] = 1;
      mst[u].push_back(id);
      mst[v].push_back(id);
    }
  }
}
void dfs(int u, int p, int id) {
  int big = -1, mx = 0;
  for (auto i : mst[u]) {
    int v = p;
    if (e[i].u == u)
      v = e[i].v;
    else
      v = e[i].u;
    if (v != p) dfs(v, u, i);
    if (v != p && s[ex[v]].size() > mx) {
      mx = s[ex[v]].size();
      big = v;
    }
  }
  if (big == -1) {
    ex[u] = u;
    for (auto i : g[u]) {
      if (!used[e[i].id]) s[u].insert(e[i]);
    }
  } else {
    ex[u] = ex[big];
    for (auto i : mst[u]) {
      int v = p;
      if (e[i].u == u)
        v = e[i].v;
      else
        v = e[i].u;
      if (v != p && v != big) {
        for (auto x : s[ex[v]]) {
          if (s[ex[u]].find(x) == s[ex[u]].end())
            s[ex[u]].insert(x);
          else
            s[ex[u]].erase(x);
        }
        s[ex[v]].clear();
      }
    }
    for (auto i : g[u]) {
      if (!used[i]) {
        if (s[ex[u]].find(e[i]) == s[ex[u]].end())
          s[ex[u]].insert(e[i]);
        else
          s[ex[u]].erase(e[i]);
      }
    }
  }
  if (id != -1 && e[id].c == 0 && ans != -1) {
    if (s[ex[u]].empty())
      ans = -1;
    else
      ans += (*s[ex[u]].begin()).c;
  }
}
int main() {
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 0; i < k; i++) {
    int a, b, c;
    scanf("%d %d", &a, &b);
    c = 0;
    a--;
    b--;
    e[i] = {a, b, c, i};
    pq.push({a, b, -c, i});
    g[a].push_back(i);
    g[b].push_back(i);
  }
  for (int i = k; i < k + m; i++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--;
    b--;
    e[i] = {a, b, c, i};
    pq.push({a, b, -c, i});
    g[a].push_back(i);
    g[b].push_back(i);
  }
  kruskall();
  dfs(0, 0, -1);
  printf("%lld\n", ans);
  return 0;
}
