虽说是水题,但是也太坑爹了吧~~~ 以前的floyd都是用的k作为内重循环,在这个题就是错了,不知道为啥,总之就是错了。调试了n久啊~ 有木有~~
#include<iostream>
#define MAXN 111
#define INF 1<<30-1
using namespace std;int map[MAXN][MAXN];
int n,m;int main()
{while( scanf( "%d",&n )!=EOF ){if( n==0 )break;int i,j,k,v;for( i=0;i<=n;i++ )for( j=0;j<=n;j++ ){map[i][j]=INF;}for( i=1;i<=n;i++ ){scanf( "%d",&m );for( j=1;j<=m;j++ ){scanf( "%d %d",&k,&v );map[i][k]=v;}}for( k=1;k<=n;k++ )for( i=1;i<=n;i++ )for( j=1;j<=n;j++ )if( map[i][j]>map[i][k]+map[k][j] && i!=j )map[i][j]=map[i][k]+map[k][j];int ansIndex=-1;int ans=INF;int maxn=0; for( i=1;i<=n;i++ ){maxn=0;for( j=1;j<=n;j++ )if( maxn<map[i][j] && i!=j )maxn=map[i][j];if( ans>maxn ){ansIndex=i;ans=maxn;}}if( ansIndex!=-1)printf( "%d %d\n",ansIndex,ans );elseprintf( "disjoint\n" );}return 0;
}