Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

求大神帮忙看下代码吧,用的floyd但是一直wa

Posted by lixuanchong at 2012-01-31 16:21:07 on Problem 1125
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator