About the Dinic algorithm of the largest stream and about the Dinic Algorithm
PART 1 What is a network stream
Network-flows is a solution to problems related to linear programming. The Theory and Application of Network streams are constantly evolving, and new topics such as gains stream, multi-terminal stream, multi-product stream, and decomposition and synthesis of network streams have emerged. Network flow has been applied in many fields such as communication, transportation, power supply, engineering planning, Task Assignment, equipment update, and computer aided design. [Taken from Baidu encyclopedia]
PART 2 Concepts
Capacity network:G (V, E) is a directed network. A vertex is specified in V, which is called the Source Vertex (recorded as Vs) and another vertex, called the sink vertex (recorded as Vt ); for each arc <u, v> belongs to E, there is a weight value c (u, v)> 0, which is called the arc capacity. generally, this Directed Network G is called a capacity network.
Arc traffic:The actual traffic on each arc in the capacity network G is recorded as f (u, v );
Maximum Flow: A Feasible Flow that satisfies the arc traffic restrictions and balances the conditions and has the maximum traffic in a capacity network. It is called the largest flow in the network.
Zengguang Road:
If f is a feasible stream in a capacity network G, P is a chain from Vs to Vt. If P meets the following conditions:
All forward arcs in a. P are non-saturated arcs,
All backward arcs in B. P are non-zero arcs.
P is an augmented path for feasible stream f.
The operations to improve the feasible stream along this augmented path are called augmented.
Residual capacity:The residual capacity on the given capacity network G (V, E) and feasible stream f, arc <u, v> is recorded as cl (u, v) = c (u, v) -f (u, v ). the residual capacity on each arc indicates the traffic that can be increased on this arc. because the traffic from vertex u to vertex v is reduced, it is equivalent to the traffic from vertex v to vertex u increasing, so each arc <u, v> there is also a reverse residual capacity cl (v, u) =-f (u, v ).
Residual network:There is a capacity network G (V, E) and its network flow f, G residual network of f is recorded as G (V ', E '). vertex set V' of G' is the same as vertex set G in G, V' = V. for any arc in G <u, v>, if f (u, v) <c (u, v), then there is an arc in G' <u, v> belongs to E' and its capacity is C' (u, v) = c (u, v)-f (u, v). If f (u, v)> 0, then there is an arc in G' <v, u> belongs to E', its capacity is C' (v, u) = f (u, v ). the residual network is also known as the residual network.
The basic idea of PART 3 Dinic algorithm:
1. Calculate the hierarchy chart based on the residual volume network.
2. Use DFS in the Hierarchy Diagram for augmented until there is no augmented path
3. Repeat the preceding steps until they cannot be extended.
PART 4 Code Introduction
1. store images with chained forward stars
2. Use bfs to layer Images
3. extended by dfs
PART 5 Template(Luogu p3376)
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <string>
# Include <algorithm>
# Include <cctype>
# Include <cmath>
# Include <cstdlib>
# Include <queue>
# Include <ctime>
# Include <vector>
# Include <set>
# Include <map>
# Include <stack>
Using namespace std;
Const int inf = 1e9 + 7;
Struct edge {
Int c, to, next;
} E [1, 210000];
Int head [11000], cnt, level [11000];
Void add (int u, int v, int w ){
E [cnt]. to = v;
E [cnt]. c = w;
E [cnt]. next = head [u];
Head [u] = cnt ++;
}
Int bfs (int s, int t ){
Memset (level,-1, sizeof (level ));
Queue <int> q;
Q. push (s );
Level [s] = 0;
While (! Q. empty ()){
Int u;
U = q. front ();
Q. pop ();
For (int I = head [u]; ~ I; I = e [I]. next ){
Int v = e [I].;
If (level [v] =-1 & e [I]. c ){
Level [v] = level [u] + 1;
Q. push (v );
}
}
}
If (level [t] =-1) return 0;
Return 1;
}
Int dfs (int u, int v, int flow ){
If (u = v) return flow;
Int res = 0;
For (int I = head [u]; ~ I; I = e [I]. next ){
Int j = e [I].;
If (level [j] = level [u] + 1 & e [I]. c ){
Int f = dfs (j, v, min (flow-res, e [I]. c ));
Res + = f;
E [I]. c-= f;
E [I ^ 1]. c + = f;
}
}
If (! Res) level [u] =-1;
Return res;
}
Int main ()
{Int n, m, I, j, k, u, w, v, s, t, ans = 0;
Cin> n> m> s> t;
Memset (head,-1, sizeof (head ));
For (I = 1; I <= m; I ++ ){
Scanf ("% d", & u, & v, & w );
Add (u, v, w );
Add (v, u, 0 );
}
While (bfs (s, t ))
While (int a = dfs (s, t, inf ))
Ans + =;
Cout <ans <endl;
Return 0;
}
Reference http://blog.csdn.net/x_y_q_/article/details/51999466
Baidu encyclopedia