HDU 1151 air raid (minimum path coverage)

Source: Internet
Author: User
Air raid

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 1904 accepted submission (s): 1225

Problem descriptionconsider a town where all the streets are one-way and each street leads from one intersection to another. it is also known that starting from an intersection and walking through town's streets you can never reach the same intersection I. e. the town's streets form no cycles.

With these assumptions your task is to write a program that finds the minimum number of paratroopers that can descend on the town and visit all the intersections of this town in such a way that more than one paratrooper visits no intersection. each paratrooper lands at an intersection and can visit other intersections following the town streets. there are no restrictions about the starting intersection for each paratrotions.

 

Inputyour program shocould read sets of data. The first line of the input file contains the number of the data sets. Each Data Set specifies the structure of a town and has the format:

No_of_intersections
No_of_streets
S1 E1
S2 E2
......
Sno_of_streets eno_of_streets

The first line of each data set contains a positive integer no_of_intersections (greater than 0 and less or equal to 120), which is the number of intersections in the town. the second line contains a positive integer no_of_streets, which is the number of streets in the town. the next no_of_streets lines, one for each street in the town, are randomly ordered and represent the town's streets. the line corresponding to street K (k <= no_of_streets) consists of two positive integers, separated by one blank: SK (1 <= Sk <= no_of_intersections) -The number of the intersection that is the start of the street, and EK (1 <= EK <= no_of_intersections)-the number of the intersection that is the end of the street. intersections are represented by integers from 1 to no_of_intersections.

There are no blank lines between consecutive sets of data. Input data are correct.

 

Outputthe result of the program is on standard output. for each input data set the program prints on a single line, starting from the beginning of the line, one INTEGER: the minimum number of paratroopers required to visit all the intersections in the town.

 

Sample input2 4 3 3 4 1 3 3 3 3 3 1 1 2 3

 

Sample output2 1

 

Sourceasia 2002, Dhaka (Bengal)

 

Recommendignatius. l each paratrowing lands at an intersection and can visit other intersections following the town streets. Is the minimum path overwrite. Attention is directed edge. The side to be added when scaling. And the result should not be divided into 2
 /*  HDU 1151  */  # Include <Stdio. h> # Include < String . H> # Include <Algorithm> # Include <Iostream> Using   Namespace  STD;  /* **************************************** * ******************************** // Bipartite Graph Matching (hungaryAlgorithm) // Initialization: G [] [] division of vertices on both sides // establish G [I] [J] to indicate the 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) //************************************** ************************************  */  //  Vertex number starting from 0  Const   Int Maxn = 150  ;  Int UN, vn; // Number of U and V  Int  G [maxn] [maxn];  Int  Linker [maxn];  Bool  Used [maxn];  Bool DFS ( Int U) //  Find the augmented path from the left  {  Int  V;  For (V = 0 ; V <VN; V ++)//  The vertex number starts from 0 and needs to be modified to start from 1.        If (G [u] [v] &! Used [v]) {used [v] = True  ;  If (Linker [v] =- 1 | DFS (linker [v]) {  //  Find zengguang Road, reverse Linker [v] = U;  Return   True ;}}  Return   False ; //  Do not forget this sentence.  }  Int  Hungary (){  Int Res = 0  ;  Int  U; memset (linker, - 1 , Sizeof (Linker ));  For (U = 0 ; U <UN; U ++ ) {Memset (used,  0 , Sizeof  (Used ));  If (DFS (u) RES ++ ;}  Return  Res ;}  //  **************************************** **************************************/  Int Main (){  Int  K;  Int  N;  Int  U, V;  Int  T; scanf (  "  % D  " ,& T );  While (T -- ) {Scanf (  " % D  " , & N ,& K); memset (G,  0 , Sizeof  (G ));  While (K -- ) {Scanf (  "  % D  " , & U ,& V); U -- ; V -- ; G [u] [v] =1  ;} Un = Vn = N; printf (  "  % D \ n  " , N- Hungary ());}  Return   0  ;} 

 

 

 

A bipartite graph is a complex modeling ....

WriteCodeAre templates .....

 

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.