Network Flow Summary

Source: Internet
Author: User

One, the maximum flow

1) Split Point

① to satisfy the individual's own limitations

POJ 3281 Dining

The maximum number of cows can be selected for the desired food and drink. Because each cow's contribution to the answer is at most one, so each cow is broken into two points, even a capacity of one side can be.

SPOJ 962 Intergalactic Map

This problem tells us that the network flow can ask whether there is a path passing through each point (each edge) no more than k times. Only need to split each point into two points, the middle of a capacity of a k-side can be.

1305: [Cqoi2009]dance dancing

Everyone dances at most with a person who doesn't like K. Split each person into a favorite and even dislike the two points, between two points has a capacity of the side of K.

SGU 438 the glorious Karlutka river =)

Each stone is to be split into 2 * t blocks, at every different point in time with two points, two points between the capacity of CI, the second point to all it can be to the point of the next moment of the first point of a capacity ∞ edge.

The problem is solved by the individual number of individual requirements, does not affect the whole, then in the individual internal disassembly and then add it to the overall network flow.

② represents the different situations after the transfer of time (space).

SGU 438 the glorious Karlutka river =)

Each stone is to be split into 2 * t blocks, at every different point in time with two points, two points between the capacity of CI, the second point to all it can be to the point of the next moment of the first point of a capacity ∞ edge.

POJ 2391 ombrophobic bovines

The problem is simple, each point is split into two points, respectively, the state before moving and the state after the move.

2) Distribution

① Competition Issues

Woj 1124 Football Coach

Each game is a point, each person is a point, each game to the source point of a 2 side, to two players each with a 2 side of the can.

SGU 326 Perspective

Similar to the previous question of the DA

POJ 2699 The Maximum number of strong Kings

After the size of the two K (here the online solution is mostly a clear error in the conclusion, if the final answer to K is feasible, it is easy to prove that there must be a set of solutions so that the largest k individuals meet the requirements, rather than satisfy the requirements of the maximum k individuals), the same is a point per game, each open a point, Set the largest K-person is strong king, some of the outcome of the game is determined, the uncertainty of the various even a side is good, to see whether the maximum flow is full.

Most of this type of problem is to give each game a point, and then try to put the game after the end of every possible to add to the chart.

② Other Assignments

This kind of problem is similar to the competition problem.

Joj 2453 Candy

Every sugar is like a game, different treatments can lead to different results, sugar can be assigned to each child and the winner of the game can be assigned to one of the participants. Finally see if it is possible to meet the plan is to give each of the children to the meeting point at least for so many to meet the conditions of the edge, if the maximum flow is full flow obviously there is a feasible solution, otherwise there is no.

3) Building Map

① selective building of edges

ZOJ 2760 how many shortest Path

Ask how many short circuits are not coincident with each other. An edge [I, j] may be an edge of any shortest path when and only if dist[s, I] + [I, J] + dist[j, t] = = The longest short-circuit length. These sides are built into the flow network, each side of the capacity of one, running side of the good.

② need to optimize the construction

POJ 1149 PIGS

/******** from Edelweiss "Network Flow modeling Summary" ********

Rule 1. If the source of traffic for several nodes is exactly the same, you can combine them into one.
Rule 2. If the flow of several nodes is exactly the same, you can combine them into one.
Rule 3. If from point u to v there is a capacity of ∞ side and point v except point u not
There are other sources of traffic, you can combine the two nodes into one.

In the face of network flow problems, if the moment can not think of a good composition method, it is better to first construct a most
Intuitive, or most "hard-to-come" models, and then use the merge nodes and edges method to simplify the
Type. After simplification, the idea of a good composition will naturally emerge. This is a solution to the network flow problem
A good way to do it.

*******************************************************/

Such problems, or the application of the law to the original complex optimization of the problem, or directly grasp the nature of the problem to build a beautiful picture, it is very difficult to feel, or to do more problems,

4) Tips

① the capacity of a certain (some) side

The two points have determined the maximum (small) value of the capacity of a certain (some) edge in the case of a viable solution.

SPOJ 287 Smart Network Administrator

Q What is the minimum amount of traffic with the largest flow in a situation where full flow can be achieved? It is easy to think of the smallest maximum, and then all sides are assigned the value of whether it is feasible.

② utilization of flow conservation

POJ 1637 Sightseeing Tour

The Euler circuit of the mixed graph is obtained. The necessary and sufficient condition of Euler loop is that the degree of each point is equal to that of the flow, which coincides with the stream conservation of network flow. Each non-edge will give two vertices one in the degree plus one, one out of the degree plus one, feel this and a game somewhat like! A better approach is to take each non-directed edge at will, and then put a point more out of the degrees to the less-than and its edge point, so that the point on each side is much faster.

The model that finds the game can do the same, assuming that one wins and then adjusts. If the other party wins, it flows a 2 edge, and if it is a draw, it flows a 1 edge, it should be possible.

Second, the smallest cut

All the rigorous proof see Amber HBT's "minimal cut model in the application of the Informatics competition" article. Here are some of my own superficial understanding.

Cut, that is, all the points are divided into S and T two parts, each point exists and only exist in S or T, and the source point belongs to S, the meeting point belongs to T.

Cut-to-flow relationship: a flow in a stream network is its flow through a cut of static flow.

Prove:

First clear: ① own flow to their own sum of 0. ② the sum of all non-source non-sink point traffic is 0.

So f (S, T) = f (S, V)-F (s, s) = f (S, V) = f (S, V) + f (s-s, V) = f (S, V) = f (S, t).

Maximum flow minimum cut theorem: As the name implies, the maximum flow in a network equals its minimum cut capacity.

Perceptual proof: Imagine a pile of flow ah flow ah, flow to the smallest cut cut edge of the front together stopped, and then forward flow, can only flow through the smallest cut capacity so much, and then more on the flow of the past, so this must be the largest solution, and before it flows through this step and all the cut through it is bigger than it , so this must be the smallest solution. In sum, the maximum flow is equal to the smallest cut.

Fractional planning

!!!!!!!!!!!!!!!!!!

Stay Pits

!!!!!!!!!!!!!!!!!!

Most powerful closed diagram

A closed graph means that no point in the graph has an edge that is not connected to the point.

#define SIMPLE cut all edges are only connected to s or only to T.

To this map s to all the points of the positive weight of an edge, the flow is VI, all negative weights of the point to the T with one edge, the flow is-vi, the other side is not moving, the flow is ∞.

So the simple cut edge of the chart is not included in the original image of any one side (this is important)

Below, the simple cut in this picture must be a closed graph, and all closed graphs must be a simple cut.

The closed diagram corresponds to a simple cut:

If the closed graph does not correspond to a simple cut, in the closed graph there will be a point from the s-s to a point in the t-t edge, the edge of the closed graph is connected to the outside, contradictions.

A simple cut corresponds to a closed diagram:

Because this is built a simple cut of the cut edge is not included in the original image of any one side, so in a simple cut, s-s all points will not be connected to the T-T, so is a closed diagram.

A simple cut capacity is the sum of the absolute values of the points of the negative weights in the s-s and the absolute sum of the points of the positive weights in the t-t.

When a simple cut is minimized, the closed graph has a minimum value.

So you can use the minimum cut to find the maximum weight of the closed graph!! ^_^

,,,,,,,, finally finished, to the back to bother to write the vernacular version of the proof because the HBT formula version of the proof is also very simple.

The application of the most powerful closed graph is still very wide.

tag in the title Description:

Positive negative right, maximum (minimum)

Examples:

①bzoj 1497: [NOI2006] maximum profit bare question

②poj 2987 Firing

The problem is to find out the maximum number of points of the closed graph under the premise of finding the smallest.

It can be proved that the minimum number of points can be obtained if the maximum weight of the closed graph is calculated and traversed again.

But there is a fantasy idea:

In the network to enlarge the edge, will Benquan *10000, if the edge and the source point s even, then the flow minus one, if the edge and the meeting point T-connected, then the flow plus one, for the original point of 0 points, and the meeting point of the T-link, the flow of 1

Set with the source point s connected to the edge has total, the minimum cut for Max_flow, then (max_flow+total)/10000 is the original minimum cut, (max_flow+total)%10000 is the Dag graph of the number of points, because in the cutting edge set, If the cutting edge and the source point s are connected, indicating that the point is not taken, cutting edge and meeting point T is connected, indicating that the point to take, so the use of the above method can ensure that the best solution is obtained

This is really very ingenious ah, worth accumulating!

③bzoj 1565: [NOI2009] Plants vs Zombies

A very interesting problem, the maximum weight of the closed graph is quite obvious, but the picture may have a ring! All the points in the ring and the precursors of all the points in the ring are unlikely to be attacked, so there is a way to eliminate these points. The idea of topological ordering of the inverse diagram for this diagram is the last point at which all topological points can be chosen.

Finally, there's a little tip:

Dinic To add this sentence when writing DFS:

if (!f) dist[v] = 0;

It's going to be a lot quicker. Because if Dfs finds that the previous capacity is already full, it will not be possible to broaden it later.

④bzoj 2127

/////////////////////////////////////////

Very unhappy!! I have seven or eight of the puzzle is swallowed by the Blog Park!!! Oh, no, I'm not in the mood to mend it anymore.

//////////////////////////////////////////

Some tips:

no forward edge. There is a useful function: If the A<-->B:C, that is, a and B with a weight of a non-forward edge of C, when this non-edge count into the minimum cut, indicating that the two points belong to the S,t two sets.

Vfleaking said in the bar:

If V-U is connected with a forward edge with a capacity of W, it means that if V is cut in S, then U is not at the cost of W in S cut.
An equivalent statement is that if you cut in T, then v does not cut at the cost of W. Note v if cut in t, then u in S cut will not incur a price.
In particular, if V-U is connected to a forward edge with a positive infinity, it means that if V is cut in S, then u must also be cut in S.
An equivalent expression is that if you cut in T, then v must also be cut in T.

Whether a one-way or two-way edge depends on the functionality you want to implement.

To summarize, there are several main edges in the minimum cut map:

    • A point is connected to the source or sink, which represents the cost of having this point divided into the first class/second class.
    • There is an edge U-V, u in S and V not at the cost.
    • Forward-side U-V (c = INF): ①u,v one side ②u, V needs to cut one of them
    • Without a forward edge u <-> v:u, V does not need to pay for the same set of costs.
    • The point right can be transferred to the source or sink connected to the Benquan, once the best reason to minimize the optimization tool to decision-making point of choice. </span>

Take a look at a picture like this:

There are a few things that can be cut in this picture:

① cut SA & SB or cut AT & BT

This represents a, B is divided into the same group, each cost their own costs.

② cut SA & AB & BT or cut SB & BA & at

At this point a, B is not divided into the same group, they need to spend their own costs and their costs in the same group.

"bzoj2132" Enclosure plan

Now that you know that this is the smallest cut, then ask for the most profit? Complement set.

Add up all the possible gains and subtract the minimum cost. Obviously, a point to build industrial areas will cost the business district money, building a business district will cost the industrial park money, in addition, if the same adjacent to spend CIJ money. The first two conditions directly on the source point and the meeting point edge is good, then the third situation? Note that in my summary above, a non-facing edge between two points represents the cost of not being in the same set, so how does it cost to deal with the same set? The answer is to turn half of the dots. Because obviously in the third case, the parity of the two points x + y is definitely different, so this is a bipartite graph, then we just put this bipartite graph in the general point completely in turn, even if the source as a sink, the sink as a source, then is two points not the same set of time to cost!!

"Bzoj2127" Happiness

At the very beginning, we must calculate the total profit, then sum up the cost of each scenario: if the two people with the choice of the text, will pay two of the cost of the person and the cost of the same election; two people a choice of a choice, you have to pay the price of a person to choose the price + the price of the election and the same choice Cost and.

The process of thinking cannot be written, the following is the conclusion of copy:

For all adjacent two people in the original, A, B, we build the edge:

S->a:cost[a Wen]+c[wen][a][b]/2,s->b:cost[b wen]+c[wen][a][b]/2;

A->t:cost[a]+c[][a][b]/2,b->t:costb[Li]+c[][a][b]/2;

a<-->b:c[Wen][a][b]/2+c[li][a][b]/2

This will appear two kinds of cut, respectively, corresponding to the same two, a selection of an election.

There are many other ways to build this problem.

Zyb took a look at the problem and said it was not done casually, how to cut it all right.

Alas, I am still too weak.

Bzoj 1797: [Ahoi2009]mincut min cut

On the remaining path, if an edge (U, v) v and T Unicom, it is indicated that there is one, if you are also connected with S, it is necessary to select this one.

It is wrong to do the above.

We think that if (U, v) this edge can be cut, it means that if you divide into S, v points to T, you can still find the maximum flow.

Force u in S method above said, is from S to u even an INF edge. If there is an augmented path after this, it means that the side can be cut off. And there is the augmented road when and only if u to V is unicom, so as long as the two points can be connected to it.

Bzoj 1391: [Ceoi2008]order

SB problem, but card dinic boingonium hindering

Some say adding current arc optimization is possible.

The current ARC optimization is when you are augmented when the edge is already full of flow and will not have to visit it, the cur set as it can.

I've used two optimizations here, and that's how it's written:

f = DFS (edge[i].to, T, Min (maxf-cnt, EDGE[I].F)), if (!f) dist[edge[i].to] = -1;edge[i].f-F; edge[i ^ 1].f + = F;if (EDGE[I].F) cur[now] = i;

Bzoj 1532: [poi2005]kos-dicing

Well, no more simple maximum flow, but the data range is large, the above optimization plus can easily be over, can be dozens of times times faster than the speed.

Bzoj 2561: Minimum spanning tree

Think of the minimum spanning tree construction process. if (U, v) this edge is not in the smallest spanning tree, you and V will be connected if and only if the edge in the selected edge is smaller than (U, v) edge.

So this problem we need to determine two conditions: ① only with a smaller than (U, v) side can not make u,v unicom. ② only with a larger than (u,v) side can not make u,v unicom.

Greedy? In a figure like this, it's obviously wrong.

Once again, be clear about what to do:

In a pile of edges, remove the fewest edges, making the two points non-interconnected.

So the smallest cut came out (^_^)

But complexity looks scary, and if I don't see it in the category of minimal cuts, I'm not going to think about it here. Later Zyb proved that the complexity is still very reliable, unable to card, but I do not understand.

Bzoj 1324:exca Sword of Kings

The amber paper has been said to be no longer clear.

Just a second thought:

Only even time can be profitable, because the odd time must be deleted at the even time of the previous step.

It can then be proved that two adjacent points cannot be selected at the same time.

Then a conjecture is whether it is possible to select two nonadjacent points at the same time.

It is possible to construct it properly.

So the problem is a simple binary graph of the maximum point right independent set.

Bzoj 1562: [NOI2009] Transform sequence

Find the maximum matching of the minimum dictionary order on a two-part graph. (The test instructions of this problem I was not understand read for a long time,,,)

If you go from the back to the next match, each point is selected as small as possible match, after the match is the smallest dictionary order scheme!

It would be nice to prove it with inductive method. If the post-N-i point has been processed, that is, the current single-n-i point is the smallest possible dictionary order. The following matches the first I point. If the first point can be matched to the smallest before it has not been used, then naturally choose it, no effect on the back. If this point has been used before, we will find an augmented road when matching, if you can find, the augmented road on the side of all to take the opposite, is obviously an optimal feasible solution, if not find the augmented road, then go to match sub-small point ...

Minimum cut algorithm for planar graphs

A plan is a graph of points at the intersection of each edge. For example, a grid is a floor plan.

Then each closed surface in the plan as a point, so that the original image of an edge of the original plane is divided into two parts representing the connection of the two sides of it. So the number of edges in the new diagram is equal to the original. And then the original image in the outside of the map, the area is the inf of the surface split into two points as the source and sink, feel will find in this new figure from the source to sink any path is a cut in the original image, so if the requirement of the smallest cut only asked once the shortest way of the new diagram! It's amazing.

Bzoj: [Noi2010] Altitude

There are two points that are certain:

① the height of all points will only be 0 or 1② all of the 0-node Unicom, all the ① node Unicom.

And because the original is a grid, it is better to use a dual graph to find the smallest cut.

Bzoj bzoj3158 close call && bzoj 3275:number

(2a+1) ^2+ (2b+1) ^2=2 (2a^2+2b^2+2a+2b+1)

Report:

My dinic template

int n, M, HEAD[MAXN], CUR[MAXN], EE =-1, DIST[MAXN], Q[MAXN], ans;struct edge{int to, Next, F;}  edge[maxm];inline void Addedge (int x, int y, int f) {edge[++ ee].to = y; edge[ee].f = f; edge[ee].next = head[x]; Head[x] = EE;} inline void Add (int x, int y) {Addedge (x, y, 1); Addedge (y, x, 1);} BOOL BFs (int s, int t) {for (int i = 1; I <= n; i + +) dist[i] = -1;int TT = 0, w = 1;dist[s] = 1; q[0] = S;while (tt! = W) { int u = q[tt ++];for (int i = head[u]; I! = 1; i = edge[i].next) if (dist[edge[i].to] = = 1 && edge[i].f) {dist[edge[ I].to] = Dist[u] + 1;if (edge[i].to = = t) return 1;q[w + +] = edge[i].to;}} return 0;} int dfs (int now, int T, int. MAXF) {int cnt = 0, f;if (now = = t) return maxf;for (int i = Cur[now]; I! =-1; i = edge[i].next) i F (dist[edge[i].to] = = Dist[now] + 1 && edge[i].f) {f = dfs (edge[i].to, T, Min (maxf-cnt, edge[i].f)); EDGE[I].F-= F edge[i ^ 1].f + = f; CNT + = f;if (!f) dist[edge[i].to] = -1;if (EDGE[I].F) Cur[now] = i;if (cnt = = MAXF) return cnt; return CNT;} void Dinic (ints, int t) {while (BFS (s, t)) {for (int i = 1; I <= n; i + +) cur[i] = Head[i]; ans + = DFS (s, T, INF);}} 

UPD:

is the network flow related to it:

Minimum chain coverage = longest anti-chain = maximum (small) number of elements.

Network Flow Summary

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.