/** * Author: Fau * Time: 2021-07-28 17:27 **/ #include #define rep(i, n) for (int i = 1; i <= (n); ++i) #define debug(a) cout << #a << " = " << a << endl using namespace std; typedef long long ll; const int N = 3E3 + 10; int n, m; int p[N], cost[N]; int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); } int main() { #ifndef ONLINE_JUDGE freopen("/Users/Fau/Documents/Fau/project/Clion Program/TEXT/in.txt", "r", stdin); freopen("/Users/Fau/Documents/Fau/project/Clion Program/TEXT/out.txt", "w", stdout); #endif //------------------------------------------------------------CODE BEGIN------------------------------------------------------------ while (~scanf("%d %d", &n, &m)) { iota(p + 1, p + 1 + n, 1); fill(cost + 1, cost + 1 + n, 0); int cou = 1; rep(i, m) { int a, b, c; scanf("%d %d %d", &a, &b, &c); if (a == b) continue; cost[a] += c, cost[b] += c; a = find(a), b = find(b); if (a != b) p[b] = a, cou++; } int fmin = 0x3f3f3f3f; rep(i, n) fmin = min(fmin, cost[i]); printf("%d\n", cou == n ? fmin : 0); } //-------------------------------------------------------------CODE END------------------------------------------------------------- #ifndef ONLINE_JUDGE fclose(stdout); system("/Users/Fau/Documents/Fau/project/Clion\\ Program/compare_Fau"); #endif return 0; }