Skip to main content

Posts

Showing posts with the label Maxflow

Minimum cost Maxflow or mincut maxflow or Successive Shortest Path source code in C++

when there is need of minimum cost along with maximum flow then comes this problem. Sometimes it called successive shortest path . Here is a problem for better understanding 10498 ************************************************************************************* #include<iostream> #include<string> #include<vector> #include<queue> #include<algorithm> using namespace std; #define MV 102 typedef long long LL; LL  cst[MV][MV],     cap[MV][MV],     par[MV],dis[MV],     source,sink,flow; vector<int>adj[MV]; struct pq{     LL d,n;     void ini(LL a,LL b){n=a;d=b;}     bool operator<(const pq &b)const{return d>b.d;} }; bool PFS(int s,int sk) {     priority_queue<pq>Q;     pq u,v;     int i;     memset(dis,50,sizeof dis);     di...

Basic Maxflow or Network Flow source code in c++

When there is one source and one sink and prospect is that to send maximum unit to sink then comes the need of maxflow.It is normally a bfs which helps to find the maximum capacity  over the line load and reduce this capacity from load until the load comes to zero.I mean until there is any path from source to sink. Here is the code for maxflow.Hope it help.  #include<cstdio> #include<cmath> #include<cstring> #include<string> #include<iostream> #include<queue> #include<algorithm> using namespace std; #define INF  2147483647 /***************** Max Flow Algorithm*************** ****************************************************/ const int maxINDX=102; int flow[maxINDX][maxINDX],cap[maxINDX][maxINDX]; int path[maxINDX]; int src,dest; int BFS(int node) {     int i,item,cf;     queue<int> q;     for(i=1;i<=node;i++)       ...