#include #include #include using namespace std; const int N = 3010,M=100010; int n,m; int p[N]; int find(int x) // 并查集 { if (p[x] != x) p[x] = find(p[x]); return p[x]; } int sum[N]; int main() { while(scanf("%d%d",&n,&m)!=EOF) { int cnt=0; memset(sum,0,sizeof sum); for(int i=1;i<=n;i++)p[i]=i; while (m -- ) { int a,b,c; scanf("%d%d%d",&a,&b,&c); if(a==b)continue; sum[a]+=c; sum[b]+=c; a=find(a),b=find(b); if(a!=b) { p[a]=b; cnt++; } } if(cnt==n-1) { sort(sum+1,sum+1+n); cout<