#include <bits/stdc++.h>   const int MAXN = 200000 + 10;   const int INF = 0x7fffffff;   using namespace std;   struct EDGE {     int u, v, w;     bool operator<(const EDGE &b) const { return w > b.w; }   };   int fa[MAXN + MAXN];   int n, m, vis[MAXN];   int Min[MAXN];   vector<EDGE> edge;   int Find(int x) { return fa[x] < 0 ? x : fa[x] = Find(fa[x]); }   int main() {     edge.clear();     scanf( %d%d , &n, &m);     memset(fa, -1, sizeof(fa));     memset(vis, 0, sizeof(vis));     for (int i = 1; i <= m; i++) {       int a, b, w;       scanf( %d%d%d , &a, &b, &w);       edge.push_back((EDGE){a, b, w});     }     sort(edge.begin(), edge.end());     long long Ans = 0ll;     for (int i = 0; i < m; i++) {       int u = edge[i].u, v = edge[i].v;       u = Find(u);       v = Find(v);       if (u == v) {         if (fa[u] == -2) continue;         fa[u] = -2;         Ans += (long long)edge[i].w;         continue;       }       if (fa[u] == -2 && fa[v] == -2) continue;       fa[v] = min(fa[v], fa[u]);       Ans += (long long)edge[i].w;       fa[u] = v;     }     printf( %lld n , Ans);     return 0;   }   