HDU 1151 Air Raid (minimum path coverage)
Bipartite Graph Matching (dfs implementation of the Hungary algorithm)
Initialization: Division of vertices on both sides of g [] []
Create g [I] [j] to indicate that the directed edge of I-> j can be used, which is the matching on the left to the right.
When g is connected without edges, the initialization is 0.
UN is the number of vertices on the left and vN is the number of vertices on the right.
Call: res = hungary (); Maximum number of output matches
Advantage: it is suitable for dense graphs. DFS is used to find augmented paths, which is concise and easy to understand.
Time Complexity: O (VE)
**************************************** ***********************************/
Vertex number starting from 0
/* HDU 1151 */# include
# Include
# Include
Using namespace std; /*************************************** * ********************************** // Bipartite Graph matching (dfs implementation of the Hungary algorithm) // initialization: Division of vertices on both sides of g [] [] // establish g [I] [j] to indicate directed edge of I-> j, it is the matching on the left to the right. If no edge is connected, the value 0 is initialized. // uN indicates the number of vertices on the left to match, and vN indicates the number of vertices on the right to match. // call: res = hungary (); Maximum number of matched outputs // advantage: Suitable for dense graphs, DFS find augmented paths, simple and easy to understand // time complexity: O (VE) //************************************** *************************************/// const int MAXN = 150 whose vertex number starts from 0; int uN, vN; // u, v Number int g [MAXN] [MAXN]; int linker [MAXN]; bool used [MAXN]; bool dfs (int u) // find the augmented path {int v; for (v = 0; v from the left