#include <bits/stdc++.h>
using namespace std;
int n;
int k;
int m;
vector<pair<int, int> > v;
struct st {
  int a;
  int b;
  long long int c;
};
vector<st> vv;
bool cmp(st a, st b) { return a.c < b.c; }
vector<pair<int, long long int> > g[500002];
int belong[500002];
inline int root(int b) {
  if (belong[b] == -1) {
    return b;
  }
  return belong[b] = root(belong[b]);
}
void merge(int a, int b) {
  a = root(a);
  b = root(b);
  if (a == b) return;
  belong[a] = b;
}
set<int> ng[500002];
long long int anss;
inline void dfs2(int b, int pr = -1, long long int ct = 0) {
  for (auto go : g[b]) {
    if (go.first == pr) continue;
    dfs2(go.first, b, go.second);
    if (ng[go.first].size() > ng[b].size()) swap(ng[go.first], ng[b]);
    for (int el : ng[go.first]) {
      if (ng[b].count(el)) {
        ng[b].erase(el);
        continue;
      }
      ng[b].insert(el);
    }
    ng[go.first].clear();
  }
  if (pr != -1 && ct == -1) {
    if (ng[b].size() == 0) {
      anss = LLONG_MIN;
      return;
    }
    anss += vv[*ng[b].begin()].c;
  }
}
int main() {
  memset(belong, -1, sizeof(belong));
  cin >> n >> k >> m;
  for (int i = 0; i < k; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    v.push_back(make_pair(a, b));
    g[a].push_back(make_pair(b, -1));
    g[b].push_back(make_pair(a, -1));
    merge(a, b);
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    vv.push_back({a, b, c});
  }
  sort(vv.begin(), vv.end(), cmp);
  vector<st> vvv;
  for (int i = 0; i < vv.size(); i++) {
    int a = vv[i].a;
    int b = vv[i].b;
    long long int c = vv[i].c;
    if (root(a) == root(b)) {
      vvv.push_back(vv[i]);
      continue;
    }
    g[a].push_back({b, c});
    g[b].push_back({a, c});
    merge(a, b);
  }
  vv = vvv;
  for (int i = 0; i < vv.size(); i++) {
    int a = vv[i].a;
    int b = vv[i].b;
    long long int c = vv[i].c;
    ng[a].insert(i);
    ng[b].insert(i);
  }
  dfs2(0);
  if (anss < 0LL) {
    anss = -1;
  }
  printf("%lld\n", anss);
  return 0;
}
