#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 10;
struct edge {
  int a, b;
  int weight;
  int in_mst;
  bool operator<(const edge &other) const { return weight < other.weight; }
};
int N, K, M, a, b, w;
vector<edge> edges;
vector<vector<edge>> mst;
struct union_find {
  vector<int> uf;
  union_find(int N) { uf.resize(N, -1); }
  int find(int n) {
    if (uf[n] < 0)
      return n;
    else
      return uf[n] = find(uf[n]);
  }
  void merge(int a, int b) {
    a = find(a);
    b = find(b);
    if (uf[a] < uf[b]) {
      uf[b] = a;
    } else if (uf[b] < uf[a]) {
      uf[a] = b;
    } else {
      uf[b] = a;
      uf[a]--;
    }
  }
};
void compute_mst() {
  sort(edges.begin(), edges.end());
  union_find uf(N);
  for (edge &e : edges) {
    if (uf.find(e.a) != uf.find(e.b)) {
      uf.merge(e.a, e.b);
      e.in_mst = 1;
      mst[e.a].push_back(e);
      mst[e.b].push_back({e.b, e.a, e.weight, e.in_mst});
    }
  }
}
int tpos;
int depth[MAXN], par[MAXN], traversal[2 * MAXN], first[MAXN];
int sparse_table[MAXN * 2][23];
void recur(int n) {
  for (int i = 0; i < mst[n].size(); ++i) {
    int to = mst[n][i].b;
    if (to != par[n]) {
      par[to] = n;
      depth[to] = depth[n] + 1;
      recur(to);
    }
  }
}
void recur2(int n) {
  first[n] = tpos;
  traversal[tpos++] = n;
  for (int i = 0; i < mst[n].size(); ++i) {
    int to = mst[n][i].b;
    if (to != par[n]) {
      recur2(to);
      traversal[tpos++] = n;
    }
  }
}
void init() {
  tpos = 0;
  N = mst.size();
  recur(0);
  recur2(0);
  for (int i = 0; i < tpos; ++i) {
    sparse_table[i][0] = traversal[i];
  }
  for (int i = 1; (1 << i) <= tpos; ++i) {
    for (int j = 0; j < tpos; ++j) {
      int half_width = 1 << (i - 1);
      int next = min(j + half_width, (int)tpos - 1);
      int cand_a = depth[sparse_table[j][i - 1]];
      int cand_b = depth[sparse_table[next][i - 1]];
      if (cand_a < cand_b) {
        sparse_table[j][i] = sparse_table[j][i - 1];
      } else {
        sparse_table[j][i] = sparse_table[next][i - 1];
      }
    }
  }
}
int lca(int u, int v) {
  int l = first[u];
  int r = first[v];
  if (l > r) {
    int temp = l;
    l = r;
    r = temp;
  }
  int diff = r - l + 1;
  int pow = (int)log2(diff);
  int range = 1 << pow;
  int cand_a = sparse_table[l][pow];
  int cand_b = sparse_table[r - range + 1][pow];
  if (depth[cand_a] < depth[cand_b]) {
    return cand_a;
  } else {
    return cand_b;
  }
}
int get_parent(int n) { return par[n]; }
int get_depth(int n) { return depth[n]; }
struct event {
  int top, weight;
  bool operator<(const event &other) const {
    int depth = get_depth(top);
    int depth2 = get_depth(other.top);
    return depth < depth2;
  }
};
vector<event> events[MAXN];
void add_event(int bottom, int top, int weight) {
  events[bottom].push_back({top, weight});
}
long long answer = 0;
priority_queue<pair<int, int>> solve_recursively(int n, bool is_var) {
  int par = get_parent(n);
  priority_queue<pair<int, int>> cur;
  for (const edge &e : mst[n]) {
    if (e.b != par) {
      priority_queue<pair<int, int>> children =
          solve_recursively(e.b, e.weight == 0);
      if (n != 0) {
        if (children.size() > cur.size()) {
          swap(cur, children);
        }
        while (children.size() > 0) {
          pair<int, int> t = children.top();
          children.pop();
          cur.push(t);
        }
      }
    }
  }
  if (n != 0) {
    for (const event &ev : events[n]) {
      cur.push(make_pair(-ev.weight, get_depth(ev.top)));
    }
    int depth = get_depth(n);
    while (!cur.empty() && cur.top().second >= depth) {
      cur.pop();
    }
    if (is_var) {
      if (cur.empty()) {
        printf("-1\n");
        exit(0);
      }
      answer += -cur.top().first;
    }
  }
  return cur;
}
int main() {
  scanf("%d %d %d", &N, &K, &M);
  mst.resize(N);
  for (int i = 0; i < K; ++i) {
    scanf("%d %d", &a, &b);
    a--;
    b--;
    edges.push_back({a, b, 0, 0});
  }
  for (int i = 0; i < M; ++i) {
    scanf("%d %d %d", &a, &b, &w);
    a--;
    b--;
    edges.push_back({a, b, w, 0});
  }
  compute_mst();
  init();
  for (const edge &e : edges) {
    if (e.in_mst == 0) {
      int mid = lca(e.a, e.b);
      add_event(e.a, mid, e.weight);
      add_event(e.b, mid, e.weight);
    }
  }
  for (int i = 0; i < N; ++i) {
    sort(events[i].begin(), events[i].end());
  }
  solve_recursively(0, false);
  cout << answer << endl;
  return 0;
}
