HDU 1151 Air Aaid minimum path Overwrite

Source: Internet
Author: User

Question:
In a town, there are m intersections and n roads. These roads are one-way and will not form a ring. Now we need some paratroopers to inspect the town,
The paratroopers can only follow the path and ask how many paratroopers are required to search all intersections. This question is converted to the most efficient solution for Directed Acyclic graphs.
The small path overwrites the problem.
Conclusion: The minimum path overwrite of a directed acyclic graph = the number of vertices of the graph-the maximum matching of the graph.
 
AC code:
[Cpp]
# Include <iostream>
Using namespace std;
 
Const int MAX = 121;
Int no_of_intersections, no_of_streets, t;
Int link [MAX]; // record the starting point of the current link to the street endpoint
Bool map [MAX] [MAX]; // store a bipartite graph. If there is a path from the start point to the end point, map [x] [y] = true; otherwise, false
Bool useif [MAX]; // records whether the intersection point is used)
 
Void getMap () // save Graph
{
Memset (map, false, sizeof (map ));
 
Int a, B;
For (int I = 1; I <= no_of_streets; I ++)
{
Cin> a> B;
Map [a] [B] = true;
}
}
 
Bool can (int t)
{
For (int I = 1; I <= no_of_intersections; I ++)
{
If (! Useif [I] & map [t] [I])
{
Useif [I] = true;
If (link [I] =-1 | can (link [I])
{
Link [I] = t;
Return true;
}
}
}
 
Return false;
}
 
Int maxMatch ()
{
Int num = 0;
 
Memset (link, int (-1), sizeof (link); // if the link is not connected, the value is-1.
For (int I = 1; I <= no_of_intersections; I ++) // search for the augmented path from the street start point
{
Memset (useif, false, sizeof (useif ));
If (can (I) num ++;
}
 
Return num;
}
 
Int main ()
{
Cin> t;
While (t --)
{
Cin> no_of_intersections> no_of_streets;
 
GetMap ();
 
Cout <no_of_intersections-maxMatch () <endl;
}
 
Return 0;
}

 


From ON THE WAY

Related Article

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.