HDU 1151 Air Raid (minimum path overlay)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1151

Air Raid

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 3951 Accepted Submission (s): 2626


Problem Descriptionconsider a town where all the streets is one-way and each street leads from one intersection to Anothe R. It is also known, starting from a intersection and walking through town's streets you can never reach the same int Ersection i.e. the town ' s streets Form no cycles.

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

Inputyour program should 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 have the format:

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

The first line of all 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, and which is the number of streets in the town. The next no_of_streets lines, one for each street in the town, is randomly ordered and represent the town ' s streets. The line corresponding to Street K (k <= no_of_streets) consists of a 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's the end of the street. Intersections is represented by integers from 1 to no_of_intersections.

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

Outputthe result of the program was on standard output. For each input data set the program prints on a, starting from the beginning of the line, one integer:the min Imum number of paratroopers required to visit all the intersections in the town.

Sample Input2433 x 3331 3 Sample Output21 Sourceasia 2002, Dhaka (Bengal) topic: In a town, there are M junction, and N Road, these roads are unidirectional, and the road will not shape Looping Now it's time to send some paratroopers to patrol the town, land at the crossroads, then the paratroopers can only walk along the road, and finally find the minimum number of paratroopers they need to search all the intersections.

Problem solving: Solving the least-path coverage of a direction-free graph.

Tip: Minimum path overlay for a non-circular graph = number of vertices of the graph-maximum number of matches

Minimum coverage point = maximum number of matches

See the code.

1#include <iostream>2#include <cstdio>3#include <cstring>4 5 using namespacestd;6 7 intmap[ -][ -],ok[ -],n,m;8 intvis[ -];9 Ten BOOLFind (intx) One { A      for(intI=1; i<=n; i++) -     { -         if(!vis[i]&&Map[x][i]) the         { -vis[i]=1; -             if(!Ok[i]) -             { +ok[i]=x; -                 return true; +             } A             Else at             { -                 if(Find (Ok[i])) -                 { -ok[i]=x; -                     return true; -                 } in             } -         } to     } +     return false; - } the  * intMain () $ {Panax Notoginseng     intt,ans,a,b; -scanf"%d",&t); the      while(t--) +     { Aans=0; thememset (Map,0,sizeof(MAP)); +Memset (OK,0,sizeof(OK)); -scanf"%d%d",&n,&m); $          for(intI=1; i<=m; i++) $         { -scanf"%d%d",&a,&b); -map[a][b]=1; the         } -          for(intI=1; i<=n; i++)Wuyi         { thememset (Vis,0,sizeof(Vis)); -             if(Find (i)) Wu             { -ans++; About             } $         } -printf ("%d\n", N-ans); -     } -     return 0; A}

HDU 1151 Air Raid (minimum path overlay)

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.