Hungarian algorithm HDU 1151 minimum path overlay = vertex number-Maximum number of matching graphs

Source: Internet
Author: User

Air RaidTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) Total Submission (s): 3617 Accepted Submission (s): 2377

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 Input
2433 41 32 3331 31 22 3

Sample Output
21st

Sourceasia 2002, Dhaka (Bengal)
Topic: Given n villages, m-Path, each path is a direction, can not be violated, ask the minimum number of paratroopers? Investigation of knowledge points: The minimum path coverage of a forward graph = number of vertices-maximum number of matches; Hungarian algorithm template
Investigation of knowledge Points: Hungarian algorithm template//graph of the minimum path coverage of the non-circular graph = vertex number-Maximum match number #include<stdio.h> #include <string.h>int girl[125],used[125]; int Line[125][125];int n,m;int Find (int x) {int j;for (J=1;J<=N;++J) {if (!used[j]&&line[x][j]) {used[j]=1;if (!girl[j]| | Find (Girl[j])) {Girl[j]=x;return 1;}}} return 0;} int main () {int t;scanf ("%d", &t), while (t--) {Int. a,b;memset (used,0,sizeof (used)); memset (line); memset (girl,0,sizeof (Girl)) scanf ("%d%d", &n,&m), for (int i=1;i<=m;++i) {scanf ("%d%d", &a,&b); Line[a][b]=1;} int count=0;for (int i=1;i<=n;++i) {memset (used,0,sizeof (used)), if (Find (i)) count++;} printf ("%d\n", N-count);} return 0;}


Hungarian algorithm HDU 1151 minimum path overlay = vertex number-Maximum number of matching graphs

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.