zju1221Risk(Flody)

Xredman posted @ Apr 12, 2010 11:47:54 PM in Algorithm with tags ZJU floyd , 1330 阅读
2158046 2010-04-13 10:34:55 Accepted 1221 C++ 0 180 HUTC_Rise Again
#include <stdio.h>      
#include <stdlib.h>       
#include <limits.h>              
#define MAXSIZE   21           
#define INF INT_MAX
int G[MAXSIZE][MAXSIZE];
int dist[MAXSIZE][MAXSIZE]; 

//求二个数之和,如果其中有一个无穷大,则返回无穷大  
#define   MAXSUM(a, b)   (((a) != INF && (b) != INF) ?  ((a) + (b)) : INF) 


int n = 20;
  
void floyd()   
{   
	int  i, j, k;    
	for (k = 1; k <= n; k++)     
		for (i = 1; i <= n; i++)    
			for (j = 1; j <= n; j++)     
			if (dist[i][k] != INF && dist[k][j] != INF && dist[i][j] > MAXSUM(dist[i][k], dist[k][j]))    
			{   
				dist[i][j] = MAXSUM(dist[i][k], dist[k][j]);   
			}   
}        


bool readin()   
{   
	int i, j;
	int cc, k;
	for(i = 1; i <= 20; i++)
	{
		for(j = 1; j <= 20; j++)
		{
			dist[i][j] = INF;
		}
		dist[i][i] = 0;
	}
	for(i = 1; i < 20; i++)
	{
		if(scanf("%d", &cc) == EOF)
			return false;
		for(j = 1; j <= cc; j++)
		{
			scanf("%d", &k);
			dist[i][k] = dist[k][i] = 1;
		}

	}
	return true;
}  

 int main(void)   
{
	int T = 1;
	int kk;
	int a, b;
	while(readin())
	{
		floyd();
		printf("Test Set #%d\n", T++);
		scanf("%d", &kk);
		while(kk--)
		{
			scanf("%d%d", &a, &b);
			printf("%d to %d: %d\n", a, b, dist[a][b]);
		}
		printf("\n");

	}
	return 0;
}

 






NCERT Urdu Sample Pa 说:
Sep 25, 2022 06:53:53 AM

Candidates can download NCERT Urdu Sample Paper 2023 Class 6 for all formats of exams held under Term-1& Term-2 such as SA1, NCERT Urdu Sample Paper Class 6 SA2, FA1, FA2, FA3, FA4 and Assignment exams. Every student who wants to know the new exam scheme of question pattern or question paper style can download the NCERT STD-6 Ibtedai Sample Paper 2023 with sample answers to get complete details of the exam.Every student who wants to know the new exam scheme of question pattern or question paper style can download the NCERT STD-6 Ibtedai Sample Paper 2023 with sample answers to get complete details of the exam.

Tripura HS Model Pap 说:
Aug 30, 2023 09:50:30 PM

Tripura Board of Secondary Education (TBSE) Responsibilities Conducting Annual Examinations for Higher Secondary Examination (H.S. +2 Stage) Arts & Commerce, Science, TBSE +2 Annual Exam go to Conduct Tripura HS Model Paper 2024 Every year Month of April, TBSE Regulate, Supervise and Develop Higher Secondary Examination in the State of Tripura. Students have Tension for the HS Annual Examination 2024. our Website Provided All TBSE HS Question Paper 2024 to makes Students as Tension Free. Important Question will help the Students for Good Preparation. Students are you Searching for TBSE 12th Class Important Question 2024, We will Provide you Previous Question Paper pdf here and also give you Complete information about it.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter