一碰到这个问题就不知道怎么排错了。。。
// zoj 1298
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (1<<30)
#define MAX (1<<9)
int arc[MAX][MAX]={0};
int main()
{
int n,m,counter=1;
while(cin>>n>>m && !(n==0 && m==0) ){
fill(arc[1],arc[1]+n*n,inf);
int tag[MAX]={1,1},dist[MAX]={0,0};
int i,k,t=n-1;
while(m--){
int a,b,l;
cin>>a>>b>>l;
arc[a][b]=arc[b][a]=l;
}
for( i=2; i<=n; ++i) dist[i]=arc[1][i];
while(t--){
int MIN=inf;
for(i=2; i<=n; ++i)
if( !tag[i]&& tag[i]<MIN){
k=i; MIN=tag[i];
}
tag[k]=1;
for(i=2; i<=n; ++i)
if( !tag[i] ) dist[i]=min(dist[i],dist[k]+arc[k][i]);
}
int MAXNUM=0;
for(i=2; i<=n; ++i)
MAXNUM=max(MAXNUM,dist[i]);
vector <int > res;
for(i=2; i<=n; ++i)
if(dist[i]==MAXNUM) res.push_back(i);
//for(i=0; i<res.size(); ++i ) cout<<res[i]<<' '; cout<<endl;
if(res.size()==1) printf("System #%d\nThe last domino falls after %.1f seconds, at key domino %d.\n\n",counter,(float)dist[ res[0] ],res[0]);
else{
MAXNUM=0;
int a,b;
for(i=0; i<res.size(); ++i)
for(k=0; k<res.size(); ++k)
if(arc[ res[i] ][ res[k] ]!=inf && arc[ res[i] ][ res[k] ]!=0){
MAXNUM=max(arc[ res[i] ][ res[k] ],MAXNUM);
//cout<<MAXNUM<<' '<<arc[ res[i] ][ res[k] ]<<endl;
a=res[i];b=res[k];
}
if(a>b) swap(a,b);
//cout<<a<<' '<<b<<endl;
//cout<<arc[ a ][ b ]<<endl;
//cout<<MAXNUM<<endl;
printf("System #%d\nThe last domino falls after %.1f seconds, between key dominoes %d and %d.\n\n",counter,dist[ res[0] ]+MAXNUM/2.0,a,b);
}
counter++;
}
return 0;
}