Follows 567.c (Total 52 lines):

/* @JUDGE_ID:4461XX 567 C */
/* A */
#include<stdio.h>
int town[20][20] ;
int Min( int a , int b )
{
	if( a == 0 ) return b ;
	else{
		if( a > b ) return b ;
		else return a ;
	}
}
void warshell( void )
{
	int i , j , k ;
	for( k=0 ; k<20 ; k++ )
		for( i=0 ; i<20 ; i++ ) /*if( town[i][k] )*/
			for( j=0 ; j<20 ; j++ ) /*if( town[k][j] )*/
		/*    if( town[i][j] == 0 || town[i][j] > town[i][k]+town[k][j] )
					town[i][j] = town[i][k] + town[k][j];*/
				if( town[i][k] && town[k][j] )
					town[i][j] = Min( town[i][j] , town[i][k] + town[k][j] ) ;
}
void main( void )
{
	int i , j , test , towna , townb , times=0 , city ;
/* freopen( "567.in" , "r" , stdin ) ;
	freopen( "567.out" , "w" , stdout ) ;*/
	while( 1 ){
		for( i=0 ; i<20 ; i++ )
			for( j=0 ; j<20 ; j++ ) town[i][j] = 0 ;
		if( scanf( "%d" , &test ) != 1 ) break ;
		else{
			for( i=0 ; i<19 ; i++ ){
				if( i!=0 ) scanf( "%d" , &test ) ;
				for( j=0 ; j<test ; j++ ){
					scanf( "%d" , &city ) ;
					town[i][city-1] = town[city-1][i] = 1 ;
				}
			}
		}
		warshell() ;
		scanf( "%d" , &test ) ;
		printf( "Test Set #%d\n" , times+1 ) ;
		times++ ;
		for( i=0 ; i<test ; i++ ){
			scanf( "%d %d" , &towna , &townb ) ;
			printf( "%2d to %2d: %d\n" , towna , townb , town[towna-1][townb-1] ) ;
		}
		putchar( '\n' ) ;
	}
}

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com