#include #include #include using namespace std; int main(){ int n, m; while(cin >> n >> m) { int *weight = new int[n]; bool **connect = new bool *[n]; for(int i = 0; i < n; i++){ connect[i] = new bool[n]; } for(int i = 0; i < n; i++){ weight[i] = 0; for(int j = 0; j < n; j++){ connect[i][j] = false; } } int u, v, w; for(int i = 0; i < m; i++){ cin >> u >> v >> w; if(u == v){ continue; } u--; v--; weight[u] += w; weight[v] += w; connect[u][v] = true; connect[v][u] = true; } // 判断连通图 queue q; q.push(0); bool *visited = new bool[n]; while(!q.empty()){ int node = q.front(); q.pop(); visited[node] = true; for(int i = 0; i < n; i++){ if(connect[node][i] > 0 and !visited[i]){ q.push(i); } } } bool end = false; for(int i = 0; i < n; i++){ if(!visited[i]){ cout << 0 << endl; end = true; break; } } if(end){ continue; } // 最小值 cout << *min_element(weight, weight + n) << endl; } }