Hdoj 1151 Air Raid "Hungarian algorithm + two min. Vertex overlay"

Source: Internet
Author: User

Air Raid

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


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 Input2 4 33 4 1 3 2 3 3 3 1 31 2 2 3

Sample Output2 1
#include <stdio.h> #include <string.h> #define MAX 550int n,m;int Map[max][max],vis[max],str[max];int Find ( int x) {int i;for (i=1;i<=n;i++) {if (Map[x][i]&&!vis[i]) {vis[i]=1;if (str[i]==0| | Find (Str[i])) {Str[i]=x;return 1;}}} return 0;} int main () {int j,i,s,t,sum;int a,b;scanf ("%d", &t), while (t--) {scanf ("%d%d", &n,&m); Memset (Map,0,sizeof ( map); memset (str,0,sizeof (str)); for (i=1;i<=m;i++) {scanf ("%d%d", &a,&b); map[a][b]=1;} Sum=0;for (i=1;i<=n;i++) {memset (vis,0,sizeof (VIS)); if (find (i)) sum++;} printf ("%d\n", N-sum);} return 0;}

Hdoj 1151 Air Raid "Hungarian algorithm + two min. Vertex 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.