HDU 1151 Air Raid (minimum path coverage)

Source: Internet
Author: User

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
    
     

 

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.