Network maximum flow algorithm-EK algorithm, maximum flow ek AlgorithmPreface
The EK algorithm is the most basic algorithm for finding the largest stream in the network and a well-understood algorithm. It can be used to solve most of the largest stream problems.
However, due to time complexity constraints, such algorithms often have the risk of TLE.Thoughts
Do yo
smallest possible incrementWuyi for(inti=t; I!=s; I=Pre[i]) theD =Min (d, Map[pre[i]][i]); - Wu //add reverse edge to update residual network - for(inti=t; I!=s; I=Pre[i]) About { $Map[pre[i]][i]-=D; -Map[i][pre[i]] + =D; - } -Maxflow + =D; A } + returnMaxflow; the } - $ the intMain () the { the intx, y, Z; the while(~SCANF ("%d%d", m, N)) - { in_CLR (Map,0); the for(intI=0; i) the { Aboutscanf"%d%d%d", x, y, z);
Original http://blog.csdn.net/a1dark/article/details/11177907Edmondskarp algorithm, abbreviated as EK algorithm, O (m^2n)because it is a beginner tutorial, so I will try to avoid complicated mathematical formulas and proofs. Also try to give a more complete code. the target group of this article is a beginner of the network flow, especially to see a variety of NB tutorials did not understand how to find the best flow of small pots of friends.The purpo
ObjectiveThe EK algorithm is the most basic algorithm to find the maximum flow of the network, and it is a better understanding algorithm, which can solve most of the maximum flow problems.However, this algorithm often has the risk of tle because of the limitation of time complexity.ThoughtRemember the solution we mentioned when we introduced the maximum flow?
For a network flow graph, each time it is found its minimum residue (can be augment
Test instructions2 1 1 2 (0,1) 20 (1,0) 10 (0) 15 (1) 202 1 1 2 represents a total of 2 nodes, the production of energy points 1, the point of energy consumption 1, the transmission of Energy Channel 2;(0,1) 20 (1,0) 10 represents (starting point, end point) the maximum transmitted energy(0) The maximum energy generated by 15 (the point of generating energy)(1) 20 (point of consumption energy) consumption of the maximum energyBeginner network flow, I want to start from the foundation; just write
up to a[i], because only from the point of entry to the point, so that the soldiers can only walk one side.The code uses templates directly, and there are two implementations of the Dinic EK algorithm. #define Inf9000000000#define EPS (double) 1e-9#define mod1000000007#define pi3.14159265358979//********************* /#endif # define N 405#define M 100005#define maxn 450# Define MOD 1000000000000000007int n,a[n],b[n],s,e,sum,maxf,m,ans[n][n],s1;st
#include #includestring.h>#include#include#includeusing namespacestd;intdp[ -][ -],pre[ -];Const inttmin=999999999;intMaxflow;voidEK (intStartintEndintN) { while(1) {Queueint>P; Q.push (1);//source point is 1, incoming team intminflow=tmin; memset (PRE,0,sizeof(pre));//Initializes an array of augmented paths, with the vertices in the title starting from 1 while(!q.empty ()) {//BFS find augmented Road intu=Q.front (); Q.pop (); for(intI=1; i){
Question: Give You n sides with the target position T. Next there are each side, including the start point, end point, and capacity;
Feeling: the first code of the largest stream. This question is a deep understanding of the ek algorithm. However, this question is a pitfall, that is, the case of duplicate borders =!
Idea: EK Algorithm
AC code:
#include
Finally, I have finished writing the template of the network stream. I have to paste a few files and use the forward star to save and save the trouble of writing the linked list, the code is definitely the most streamlined in the code you can find
// Ek# Include # Include Using namespace STD;# Include # Define maxn300# Define maxflow 2000000000Int N, S, T, M, flow [maxn + 1] [maxn + 1], map [maxn + 1] [maxn + 1], pre [maxn + 1];Void Init (){Int I, A,
is a-a-to-a-water can flow in a circle.InputThe input includes several cases.For each case, the first line contains the space-separated integers, n (0 OutputFor each case, output a single integer and the maximum rate at which water may emptied from the pond.Sample Input5 41 2 401 4 202 4 202 3 303 4 10Sample Output50Test instructions: There are N roads, m points, let you find out that 1 is the source point, M is the maximum flow of the sink point;Idea: A typical algorithm for maximum flow-grace
is now demanded. There are multiple power plants and consumers.Analysis:Add a new point as the source point, an arc to each power station, and a weight of maximum production capacityA new point is added as a meeting point, and each consumer gives it an arc, which is the maximum power consumption.All other points, no matter what, can be regarded as the dispatch station, that is, enter equals output.The composition is completed, the maximum flow algorithm is used to solve the problem, take up the
[Cpp]# Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include # Include Using namespace std;Int max (int a, int B) {return a Int min (int a, int B) {return a> B? B: ;}# Define V 205# Define INF 0x3f3f3fInt cap [V] [V], flow [V] [V]; // cap indicates the capacity of each edge, and flow indicates the traffic of each edge.Int res [V], father [V]; // res [] indicates the remaining traffic
POJ-3281 Dining (isap ek Dinic)
There are nheaded cattle, F kinds of food, D kinds of drinks, each type of food and drink only oneNow, I will show you the foods and drinks that each ox loves. I will ask you how many cows can get their favorite foods and drinks at most.
Solution: Split the ox into two points. The weight is 1. One item is connected to the favorite food, the weight is 1, and the other is connected to the favorite drink. The weight is 1.C
graph theory algorithm-Network maximum flow template "Ek;dinic"ek TemplatesIncrease traffic by finding the minimum residue in the augmented residual network every timeconst int Inf=1e9;int n,m,s,t;struct node{int v,cap;}; vectorDinic templatesConstruct hierarchy + Block flow augmentationconst int Inf=1e9;int n,m;int s,t;int tot=1;struct node{int v,f,nxt;} E[1000010];int head[100010];int lev[100010];//Rec
Topic: Given an n-point m-edge of the graph, each edge has a capacity to increase the cost of C, representing the cost of 1 per capacity expansion, the maximum flow and the maximum flow to expand the minimum cost of KFirst ask direct run Max FlowThe second question is to connect the starting point of each edge to the end of a traffic is positive infinity, the cost of C of the edge and then the N to the meeting point of a traffic for the ans+k cost of 0 of the edge run the minimum cost maximum fl
Question connection
I started to learn about the network stream. I did not know how to create this picture when I started this question.
It is very important to create a network flow graph. After the graph is created, the problem is solved. It is indeed difficult to create a graph.
Click Open Link
Take a look at this sketch:
According to the actual meaning: it should be the graph on the left (a network with multiple source nodes and multiple sink points), which can be converted into a single s
();for (int i=head[u]; ~i; i= Nxt[i]) {int v =pnt[i];if (!a[v] Cap[i] > 0) {A[v]=min (Cap[i],a[u]);Pre[v]=i;//At this time the pre is also record the current point of the label, remember to use the chain forward to the star when this is I! Q.push (v);}}if (a[t]) break;}if (!a[t]) break;Flow + = A[t];for (int i,u=t;u!=s;u = pnt[i^1]) {//This part of the update is also. To understand the chain forward to the star is OK! i = Pre[u];Cap[i]-= a[t];//At this time I omitted the flow, only use the tra
Drainage ditches
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)Total submission (s): 8599 accepted submission (s): 4005
Problem descriptionevery time it rains on Farmer John's fields, a pond forms over Bessie's favorite clover patch. this means that the clover is covered by water for awhile and takes quite a long time to regrow. thus, Farmer John has built a set of drainage ditches so that Bessie's clover patch is never covered in water. instead, the water is d
station. (a) B. Indicates that the consumption station a can consume a maximum of B capacity.Finally ask you, from the power station, to the consumption stations, the maximum can transfer how much traffic.Obviously, this is a maximum flow template problem, we just add the super source and meeting point. Connect the given power station to the super source and connect the consumed war to the super sink. The problem will be solved.#include Copyright NOTICE: This article for Bo Master original art
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.