Follows 423.c (Total 60 lines):

/* @JUDGE_ID:4461XX 423 C "warshall" */
/* A */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define MAX 100

int map[MAX][MAX] , n ;

void Input( void )
{
	char in_tmp[1000] , *p ;
	int i , j ;

	memset( map , 0 , sizeof( map ) ) ; /* initial */

	for( i=1 ; i<n ; ++i ){
		gets( in_tmp ) ;

		for( j=0,p=strtok( in_tmp , " " ) ; j<i ; ++j,p=strtok( NULL , " " ) )
			if( *p!='x' )
				map[i][j] = map[j][i] = atoi( p ) ; /* make map[][] */
	}
}
void Output( void )
{
	int i,max ;

	for( i=1,max=0 ; i<n ; ++i )
		if( map[0][i]>max )
			max = map[0][i] ;

	printf( "%d\n" , max ) ;
}
void Warshall( void )
{
	int i , j , k ;

	for( k=0 ; k<n ; ++k )
		for( i=0 ; i<n ; ++i )
			for( j=0 ; j<n ; ++j )
				if( map[i][k]&&map[k][j] )
					if( !map[i][j] )
						map[i][j] = map[i][k]+map[k][j] ;
					else
						map[i][j] = map[i][j]<map[i][k]+map[k][j]?map[i][j]:map[i][k]+map[k][j] ;
}
void ToRun( void )
{
	Input() ;
	Warshall() ;
	Output() ;
}
int main( void )
{
	while( scanf( "%d\n" , &n )==1 ) ToRun() ;

	return 0 ;
}

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