Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
求大神帮忙看下代码吧,用的floyd但是一直wa#include<iostream> #define INFINITE (0x0FFFFFFF) #define NOT_EXIST (0x80000001) using namespace std; int Dist[200][200]; int main() { freopen("test.txt","r",stdin); int N; while( cin >> N ) { if( N == 0 ) { break; } //clear for( int i = 1 ; i <= N ; ++i ) { for( int j = 1 ; j <= N ; ++j ) { if( i == j ) { Dist[i][j] = 0; } else { Dist[i][j] = INFINITE; } } } //get the matrix for( int i = 1 ; i <= N ; ++i ) { int n_c; cin >> n_c; while( n_c-- ) { int c; int t; cin >> c >> t; Dist[i][c] = t; } } //Floyd for( int start = 1 ; start <= N ; ++ start ) { for( int end = 1 ; end <= N ; ++ end ) { if( start != end ) { for( int inter = 1 ; inter <= N ; ++inter ) { if( Dist[start][inter] + Dist[inter][end] < Dist[start][end] ) { Dist[start][end] = Dist[start][inter] + Dist[inter][end]; } } } } } //output int min = INFINITE; int max = 0; int index = -1; for( int i = 1 ; i <= N ; ++i ) { max = 0; for( int j = 1 ; j <= N ; ++j ) { if( Dist[i][j] > max ) { max = Dist[i][j]; } } if( max < min ) { min = max; index = i; } } if( min == INFINITE ) { cout << "disjoint" << endl; } else { cout << index << " " << min << endl; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator