Problem Model:
Given a weighted graph of direction, satisfies:
(1) capacity constraints:
(2) flow balance conditions:
(2) in addition to the Yuanhui, all points meet the flow balance condition, the G is a Yuanhui network, otherwise, that is, there is no Yuanhui, all points meet the flow balance condition, the " G " is no sink network.
This kind of problem is solved by easy to difficult one by one:
Question [1] a feasible flow with upper and lower bounds for a network without Yuanhui
Because the nether is a definite value that must be met for a flow on an arc. The concept of the necessary arcs is introduced below: the necessary arcs are arcs with a certain flow to fill. The structure of the necessary arc, the restriction of the lower limit of capacity is separated, thus constructing a network G' without the Nether:
1. Separate the original Arc (u,v) from a necessary arc:. (indicated in red)
2. Original arc:.
As the necessary arc has a certain limit of full, the necessary arc "pull" out to focus on the consideration:
Add additional source x, additional sinks y. Imagine an open-ended (y, x), with the necessary arcs to "string" them up, that is, to have the necessary arc (u, v),add (u, y),( x, V), volume for the necessary arc capacity. In this way, an equivalent network is established.
A scheme for a viable flow without a sink network must be the necessary arc is full. If (y, x) is removed, the maximum flow of the additional source x to the additional sink Y can make the arc of x or y full, filling the original with a viable flow.
Question [2] a feasible flow with upper and lower bounds for a network without Yuanhui
Algorithm:
1. Construct a new network according to the above method ( separating necessary arcs, attaching Yuanhui )
2. Find the maximum flow of additional source x to the additional sink y
3. If the arc of X or the arc of Y is full, then there is a solution to merge the necessary arcs back into the original, otherwise, no solution.
zoj2314 (no sink points have the upper and lower bounds of the feasible flow of judgment)
Code:
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < queue>const int MAXN =505;const int maxm=440020;const int inf=0x3f3f3f3f;using namespace std;struct Edge {int To,ca P,flow,next;} Edge[maxm];int head[maxn],tot,gap[maxn],d[maxn],cur[maxn],que[maxn],p[maxn];int n;int id[MAXM];void init () {tot=0; memset (head,-1,sizeof (Head));} void Addedge (int u,int v,int c,int d) {edge[tot]= (edge) {V,c,0,head[u]}; id[d]= Head[u] = tot++; Edge[tot]= (Edge) {u,c,c,head[v]}; HEAD[V] = tot++;} int isap (int source,int sink,int N) {memset (gap,0,sizeof (GAP)); Memset (d,0,sizeof (d)); memcpy (cur,head,sizeof (head)); int top = 0,x = Source,flow = 0; while (D[source] < N) {if (x = = sink) {int Min = inf,inser=0; for (int i = 0; i < top; ++i) {if (min > Edge[p[i]].cap-edge[p[i]].flow) {min = Edge[p[i]].cap-edge[p[i]].flow; Inser = i; }} for (int i = 0; i < top; ++i) {edge[p[i]].flow + = Min; Edge[p[i]^1].flow = Min; } if (min!=inf) flow + = Min; top = Inser; x = edge[p[top]^1].to; Continue } int ok = 0; for (int i = cur[x]; i =-1; i = edge[i].next) {int v = edge[i].to; if (Edge[i].cap > edge[i].flow && d[v]+1 = = D[x]) {OK = 1; CUR[X] = i; p[top++] = i; x = edge[i].to; Break }} if (!ok) {int Min = N; for (int i = head[x]; i =-1; i = edge[i].next) {if (Edge[i].cap > Edge[i].flow && d[edge[i].to] < min) {min = d[edge[i].to]; CUR[X] = i; }} if (--gap[d[x] = = 0) break; GAP[D[X] = min+1]++; If(x! = source) x = edge[p[--top]^1].to; }} return flow;} int main () {//Freopen ("In.txt", "R", stdin); int t,m,ss; int a,b,low,up; int D[MAXN]; int L[MAXM]; scanf ("%d", &t); while (t--) {init (); Memset (d,0,sizeof (d)); ss=0; scanf ("%d%d", &n,&m); for (int i=1;i<=m;i++) {scanf ("%d%d%d%d", &a,&b,&low,&up); Addedge (A,b,up-low,i); D[a]+=low; D[b]-=low; L[i]=low; } for (int i=1;i<=n;i++) {if (d[i]>0) {Addedge (i,n+1,d[i],0); Ss+=d[i]; } else Addedge (0,i,-d[i],0); } if (Isap (0,n+1,n+2) ==ss) {printf ("yes\n"); for (int i=1;i<=m;i++)//last output feasible stream printf ("%d\n", Edge[id[i]].flow+l[i]); } else printf ("no\n"); } return 0;}
Question [2] the Yuanhui network has a feasible flow of upper and lower bounds
Join the Edge (T, s), the lowerbound is 0 ( guaranteed not to attach Yuanhui x, y), unlimited upper bound, the problem [2] into the problem [1] to solve.
Question [3] Yuanhui Network has a maximum flow of upper and lower bounds
Algorithm:
1. First convert to question [2] to solve a feasible flow. If no solution is feasible, exit. Because the necessary arcs are separated, the necessary arcs (additional Yuanhui and their adjacent edges) and their currents can be deleted temporarily. Then delete (t,s) and restore the Yuanhui.
2. Again, find the augmented orbit from S to T , and seek the maximum flow.
3. Finally, the temporarily deleted nether information is restored and merged into the current diagram. Output solution.
This neither destroys the Nether ( separated ) nor exceeds the upper bound ( step 2 satisfies the capacity limit ) , problem solving.
Question [4] Yuanhui Network has a minimum flow of upper and lower bounds
Algorithm:
1. The same question [3].
2. From T to S to find the augmented orbit, continuous improvement.
3. The same question [3].
Question [3] and the other simple method of the question [4] :
Notice the problem [2] , the constructed (T, s), the upper and lower bounds almost no limit. Here's a look at the nature of it:
Theorem: If there is a feasible flow from S to t with a flow of F, then an arc from T to S (T, s), whose flow is lower than B (t, s) = A, then the graph must have a viable flow without Yuanhui: Except for the arc (t , s), and the capacity of the remaining edges is the same as F.
Proof: If the maximum flow from S to T is Amax, then from T to s a lower bound B (t, s) = a ' > Amax arc (T, s), then there is no viable flow without Yuanhui in this reconstructed diagram: Otherwise the arc in this feasible flow (T, s) Besides, we get the flow of S to T in the original image, which is greater than the maximum flow amax, which creates contradiction.
You can enumerate this parameter a, the nether B (t, s), each time using the question [1] to determine if there is a viable stream. This allows you to find the maximum flow.
Similarly, the problem [4] requires a minimum flow, as long as the upper bound of the binary enumeration C (T, s) can be.
Because of the naïve pre-flow propulsion Algorithm O (N3), the total complexity is O (N3 log2 flow ) .
Ideas:
No Yuanhui ( additional Yuanhui + max Resolution )
With Yuanhui ( additional (t,s) , no Yuanhui )
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Maximum flow solution with upper and lower bounds