#include #include using namespace std; const int N = 3010,M = 100010; int n,m; int p[N],res[N]; int find(int x) { if(x!=p[x]) p[x]=find(p[x]); return p[x]; } int main() { while(scanf("%d%d",&n,&m)!=EOF) { for(int i=1;i<=n;i++) { p[i]=i; res[i]=0; } int u,v,ans=1; while(m--) { int a,b,c; cin>>a>>b>>c; if(a==b) continue; u=find(a),v=find(b); res[a]+=c,res[b]+=c; if(u!=v) { ans++; p[u]=v; } } if(ans==n) { sort(res+1,res+n+1); printf("%d\n",res[1]); } } }