Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this c + + program is about Ford - Fulkerson Algorithm for Maximum Flow Problem can someone help me to make this with python? #include

this c++ program is about Ford-Fulkerson Algorithm for Maximum Flow Problem
can someone help me to make this with python?
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define V 15
bool bfs(int rGraph[V][V], int s, int t, int parent[]){
bool visited[V];
memset(visited,0, sizeof(visited));
queue q;
q.push(s);
visited[s]= true;
parent[s]=-1;
while (!q.empty()){
int u = q.front();
q.pop();
for (int v =0; v < V; v++){
if (visited[v]== false && rGraph[u][v]>0){
q.push(v);
parent[v]= u;
visited[v]= true;
}
}
}
return (visited[t]== true);
}
int findDisjointPaths(int graph[V][V], int s, int t){
int u, v;
int rGraph[V][V];
for (u =0; u < V; u++){
for (v =0; v < V; v++){
rGraph[u][v]= graph[u][v];
}
}
int parent[V];
int max_flow =0;
vector> all_path;
while (bfs(rGraph, s, t, parent)){
vector current_path;
int path_flow = INT_MAX;
for (v = t; v != s; v = parent[v]){
u = parent[v];
path_flow = min(path_flow, rGraph[u][v]);
}
for (v = t; v != s; v = parent[v]){
u = parent[v];
current_path.insert(current_path.begin(), v);
rGraph[u][v]-= path_flow;
rGraph[v][u]+= path_flow;
if (v != t && v != s){
for (int temp =0; temp < V; temp++){
rGraph[temp][v]=0;
rGraph[v][temp]=0;
}
}
}
max_flow += path_flow;
all_path.push_back(current_path);
}
cout << endl << max_flow;
for (int temp =0; temp < all_path.size(); temp++){
cout << endl << s <<"";
for (int ttemp =0; ttemp < all_path[temp].size(); ttemp++){
cout << all_path[temp][ttemp]<<"";
}
}
return max_flow;
}
int main(){
//V E
int vertex, edge;
cin >> vertex >> edge;
int s, t;
cin >> s >> t;
int graph[V][V]={0};
for (int temp =0; temp < edge; temp++){
int a, b;
cin >> a >> b;
graph[a][b]=1;
}
findDisjointPaths(graph, s, t);
return 0;
}
here is some example input:
The first line of input consists of two positive integers separated by a space, representing the number of vertices and edges in G respectively.
The second line of input consists of two positive integers separated by a space, representing the starting point and endpoint of the path.
Following that, each line contains two integers (a, b) representing an edge from node a to node b.
INPUT #1
68
14
12
16
26
23
34
35
54
63
OUTPUT #1
1
126354
INPUT #22
69
41
21
32
35
43
45
56
61
62
63
OUTPUT #2
2
4321
4561
thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

81/3 % of what amount is $10?

Answered: 1 week ago

Question

How does selection differ from recruitment ?

Answered: 1 week ago

Question

Explain the legal environments impact on labor relations. page 631

Answered: 1 week ago