Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Plese fix the code. I don't know why it don't work, it does not give me ouput, like below. here is the what the output
Plese fix the code. I don't know why it don't work, it does not give me ouput, like below.
here is the what the output of the program should be:
here what I got so far. It don't wok. Thank you.
#include#include #include #include #include using namespace std; #define V 1000 bool findAugmentingPath(int n, int s, int t, int *rGraph, int path[]) { bool visited[V]; memset(visited, 0, sizeof(visited)); queue int> q; q.push(s); visited[s] = true; path[s] = -1; // Standard BFS Loop while (!q.empty()) { int u = q.front(); q.pop(); for (int v=0; v if (visited[v]==false && *(rGraph + u*n + v) > 0) { q.push(v); path[v] = u; visited[v] = true; } } } return (visited[t] == true); } // do not change the parameters in this function. void maximum_flow(int n, int s, int t, int *capacity, int *flow)//this is the function prototype that professor gave. { int i, j, res_cap[n][n], path[n]; // to hold residual capacity and BFS' augmenting path int min_flow_path = INT_MAX; // to hold the min of the augmenting path // Assign residual capacity equal to the given capacity for (i = 0; i for (j = 0; j while (findAugmentingPath(n, s, t, &(res_cap[0][0]), path)) { // find min of the augmenting path for (j = t; j != s; j = path[j]) { i = path[j]; min_flow_path = min(min_flow_path, res_cap[i][j]); } // update residual capacities and flows on both directions for (j = t; j != s; j = path[j]) { i = path[j]; if(*(capacity + i*n + j) > 0) *(flow + i*n + j) += min_flow_path; else *(flow + j*n + i) -= min_flow_path; res_cap[i][j] -= min_flow_path; res_cap[j][i] += min_flow_path; } } } // do not modify main. Also professor gave to test the program. int main(void) { int cap[1000][1000], flow[1000][1000]; int i,j, flowsum; for(i=0; ifor( j =0; jfor(i=0; ifor( j=i+1; jfor(i=1; ifor(i=500; i for( i=754; ifor(i=0; ifor(j=0; jif( flow[i][j] > cap[i][j] ) { cout for(i=0; ifor(i=0; i Outflow of 0 is 10, should be 10 Inflow of 999 is 10, should be 10 End Test
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started