//wtrl,everybody hangbeat me #include /*#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include*/ using namespace std; typedef long long ll; typedef pair pii; typedef vector vii; typedef vector vi; typedef vector vll; typedef vector vvi; typedef pair pll; /*=====================================================================*/ #define pb push_back #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(s) (s).begin(),(s).end() #define repd(i,n) for(int i=n-1;i>=0;i--) #define forn(i,p,n) for(int i=p;i<=n;i++) #define ford(i,p,n) for(int i=n;i>=p;i--) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i) #define INF 1e9 #define PI acos(-1) /*=====================================================================*/ string int_to_string(ll n) { string s=""; while(n) { ll now=n%10; s+=now+'0'; n/=10; } reverse(s.begin(),s.end()); return s; } ll string_to_int(string s) { ll n=0; rep(i,s.size()) { n*=10; n+=s[i]-'0'; } return n; } /*======================================================================*/ const int dx[]={-1,0,1,0}; const int dy[]={0,-1,0,1}; const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; //think twice,code once //think once,debug forever int n,m; int dist[3010][3010]; bool use[3010]; void dfs(int now) { use[now]=1; forn(i,1,n) { if(dist[now][i]!=INF&&!use[i]) { dfs(i); } } } void solve() { while(cin>>n>>m) { forn(i,1,n) { use[i]=0; forn(j,1,n) { dist[i][j]=0; } } rep(i,m) { int a,b,c; cin>>a>>b>>c; if(a==b) { continue; } dist[a][b]+=c; dist[b][a]+=c; } dfs(1); bool ok=0; forn(i,1,n) { if(!use[i]) { cout<<0<>t; while(t--) { solve(); } return 0; } /* 注意数组越界,vector长度为0的时候循环会RE 注意输入顺序 注意循环时int*int爆ll 注意答案存爆ll 存答案用string过慢,最好直接输出或者用vector memset是O(n) */