func_code_string: #include <bits/stdc++.h>   using namespace std;   long long n, k, m, x[500010], y[500010], xx[500010], yy[500010], zz[500010];   const long long N = 2e6 + 10;   struct link {     long long top, fi[N], to[N], la[N], ne[N];     void clear() {       top = 0, memset(fi, 0, sizeof fi), memset(la, 0, sizeof la),       memset(to, 0, sizeof to), memset(ne, 0, sizeof ne);     }     void add(long long x, long long y) {       top++, to[top] = y;       if (fi[x] == 0)         fi[x] = top;       else         ne[la[x]] = top;       la[x] = top;     }   } L;   long long fa[N], vis[N], FA[N], dep[N], need[N], cost[N], out;   long long find(long long x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }   void dfs(long long x) {     vis[x] = 1;     for (long long i = L.fi[x]; i; i = L.ne[i])       if (L.to[i] != FA[x]) {         dep[L.to[i]] = dep[x] + 1;         need[L.to[i]] = (i <= (k * 2));         FA[L.to[i]] = x;         dfs(L.to[i]);       }   }   signed main() {     scanf( %lld%lld%lld , &n, &k, &m);     L.clear();     for (long long i = 1; i <= n; i++) fa[i] = i;     for (long long i = 1; i <= k; i++) {       scanf( %lld%lld , &x[i], &y[i]);       long long fx = find(x[i]), fy = find(y[i]);       fa[fx] = fy;       L.add(x[i], y[i]);       L.add(y[i], x[i]);     }     for (long long i = 1; i <= m; i++) {       scanf( %lld%lld%lld , &xx[i], &yy[i], &zz[i]);       long long fx = find(xx[i]), fy = find(yy[i]);       if (fx != fy) {         L.add(xx[i], yy[i]);         L.add(yy[i], xx[i]);         fa[fx] = fy;       }     }     dfs(1);     for (long long i = 1; i <= n; i++) fa[i] = i;     for (long long i = 1; i <= m; i++) {       long long fx = find(xx[i]), fy = find(yy[i]);       while (fx != fy) {         if (dep[fx] < dep[fy]) swap(fx, fy);         cost[fx] = zz[i];         fa[fx] = FA[fx];         fx = find(fx);       }     }     for (long long i = 1; i <= n; i++)       if (need[i]) {         if (!cost[i]) {           puts( -1 );           return 0;         }         out += cost[i];       }     printf( %lld , out);     return 0;   }   