View the step-by-step solution to:

please check this problem of program challenges book #include <stdio.h> #include <math.h> #define MAX 102 #define NEGINF -10000 #define

please check this problem of program challenges book



#include <stdio.h>
#include <math.h>

#define MAX 102
#define NEGINF -10000

#define max(a, b) ( (a > b) ? (a) : (b) )
#define min(a, b) ( (a < b) ? (a) : (b) )

long passengers[MAX][MAX];

void init( long roads ) {
long i, j;
for( i = 1; i <= roads; ++i )
for( j = 1; j <= roads; ++j )
passengers[i][j] = NEGINF;
}
int main()
{
long cities, roads, road1, road2;
long i, j, k, scinario = 0;
long source, des, totalPassengers;
scanf( "%ld%ld", &cities, &roads );
while( cities && roads )
{
init( roads );
for( i = 0; i < roads; ++i ){
scanf( "%ld%ld", &road1, &road2 );
scanf( "%ld", &passengers[road1][road2] );
passengers[road2][road1] = passengers[road1][road2];
}
scanf( "%ld%ld%ld", &source, &des, &totalPassengers );
for( k = 1; k <= cities; ++k )
for( i = 1; i <= cities; ++i )
for( j = 1; j <= cities; ++j )
passengers[i][j] = max( passengers[i][j], min( passengers[i][k], passengers[k][j]));

printf( "Scenario #%ldnMinimum Number of Trips = %.0lfnn", ++scinario,
ceil( double(totalPassengers) / ( passengers[source][des] - 1 )));

scanf( "%ld%ld", &cities, &roads );
}
return 0;
}#include <stdio.h>
#include <math.h>

#define MAX 102
#define NEGINF -10000

#define max(a, b) ( (a > b) ? (a) : (b) )
#define min(a, b) ( (a < b) ? (a) : (b) )

long passengers[MAX][MAX];

void init( int roads ) {
int i, j;
for( i = 1; i < MAX; ++i )
for( j = 1; j < MAX; ++j )
passengers[i][j] = 0;
}

int main()
{
long cities, roads, road1, road2;
long i, j, k, scinario = 0;
long source, des, totalPassengers;
scanf( "%ld%ld", &cities, &roads );
while( cities && roads )
{
init( roads );
for( i = 0; i < roads; ++i ){
scanf( "%ld%ld", &road1, &road2 );
scanf( "%ld", &passengers[road1][road2] );
passengers[road2][road1] = passengers[road1][road2];
}
scanf( "%ld%ld%ld", &source, &des, &totalPassengers );
for( k = 1; k <= cities; ++k )
for( i = 1; i <= cities; ++i )
for( j = 1; j <= cities; ++j )
passengers[i][j] = max( passengers[i][j], min( passengers[i][k], passengers[k][j]));

printf( "Scenario #%ldnMinimum Number of Trips = %.0lfnn", ++scinario,
ceil( double(totalPassengers) / ( passengers[source][des] - 1 )));

scanf( "%ld%ld", &cities, &roads );
}
return 0;
}

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question