#include #include #define M 100010 #define N 3005 using namespace std; int n,m; struct u2003{ int b,nx,va; }e[2*M]; int head[N],last=1; inline void build(int a,int b,int c){ e[++last].b=b; e[last].nx=head[a]; head[a]=last; e[last].va=c; } inline bool scan(){ if(scanf("%d%d",&n,&m)==EOF)return 0; last=1; memset(head,0,4*(n+2)); for(int i=1;i<=m;i++){ int a,b,c; scanf("%d%d%d",&a,&b,&c); if(a==b)continue; build(a,b,c); build(b,a,c); } return 1; } int dfn[N],low[N]; int times; void tarjan(int x){ dfn[x]=low[x]=++times; for(int i=head[x];i;i=e[i].nx){ int y=e[i].b; if(!dfn[y])tarjan(y); } } inline int suan(){ times=0; memset(dfn,0,4*(n+2)); tarjan(1); for(int i=1;i<=n;i++) if(!dfn[i])return 0; int ans=0x3f3f3f3f; for(int x=1;x<=n;x++){ int zhi=0; for(int i=head[x];i;i=e[i].nx) zhi+=e[i].va; if(zhi)ans=ans