func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<pair<int, int>> g[500010];   int rad[2][500010], tata[500010], niv[500010];   char in[500010], vaz[500010], tip[500010];   struct edge {     int x, y, c;   };   edge v[500010];   int radacina(int x, int t) {     int y = x;     while (y != rad[t][y]) y = rad[t][y];     while (rad[t][x] != y) {       int aux = rad[t][x];       rad[t][x] = y;       x = aux;     }     return y;   }   void unite(int x, int y) {     x = radacina(x, 0);     y = radacina(y, 0);     rad[0][x] = y;   }   void dfs(int nod) {     vaz[nod] = 1;     for (int i = 0; i < g[nod].size(); i++) {       int vec = g[nod][i].first;       if (vaz[vec] == 1) continue;       niv[vec] = niv[nod] + 1;       tata[vec] = nod;       tip[vec] = g[nod][i].second;       dfs(vec);     }   }   int main() {     int n, k, m, x, y;     long long sol = 0;     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i <= n; i++) rad[0][i] = rad[1][i] = i;     for (int i = 1; i <= k; i++) {       scanf( %d%d , &x, &y);       unite(x, y);       g[x].push_back({y, 1});       g[y].push_back({x, 1});     }     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &v[i].x, &v[i].y, &v[i].c);       if (radacina(v[i].x, 0) != radacina(v[i].y, 0)) {         unite(v[i].x, v[i].y);         in[i] = 1;         g[v[i].x].push_back({v[i].y, 0});         g[v[i].y].push_back({v[i].x, 0});       }     }     dfs(1);     tata[1] = 1;     int nr = 0;     for (int i = 1; i <= m; i++) {       if (in[i] == 1) continue;       x = v[i].x;       y = v[i].y;       x = radacina(x, 1);       y = radacina(y, 1);       while (x != y) {         if (niv[x] < niv[y]) swap(x, y);         sol += tip[x] * v[i].c;         nr += tip[x];         rad[1][x] = tata[x];         x = radacina(x, 1);       }     }     if (nr < k)       printf( -1 );     else       printf( %I64d , sol);     return 0;   }   