#include using namespace std; const int MAX_N = 1e5+10; int n,m,u[MAX_N],v[MAX_N],sum[MAX_N]; int father[MAX_N]; int get(int x){ while(x!=father[x]){ x = father[x]; } return x; } int main(){ ios::sync_with_stdio(0); while(cin>>n>>m){ int ans = 0; memset(sum,0,sizeof(sum)); for(int i=1;i<=n;i++){ father[i] = i; } for(int i=1;i<=m;i++){ int a,b,w; cin>>a>>b>>w; if(a==b){ continue; } sum[a] += w; sum[b] += w; a = get(a); b = get(b); if(a!=b){ ans++; father[a] = b; } } if(ans==n-1){ sort(sum+1,sum+n+1); cout<