Air Raid
Time limit:1 Sec Memory limit:256 MB
Topic Connection http://acm.hdu.edu.cn/showproblem.php?pid=1151
Descriptionconsider a town where all the streets is one-way and each of the street leads from one intersection to another. It is also known this starting from a intersection and walking through town's streets you can never reach the same inters Ection 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. Output
The 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 3 3 4 1 3 2 3 3 3 1 3 1 2 2 3Sample Output2 1
HINT
Test instructions
Find some paths in the graph to overwrite all the vertices in the graph
Exercises
Minimum path overlay = number of vertices of the graph-maximum number of matches
Code:
//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 2001#defineMoD 10007#defineEPS 1e-9//const int INF=0X7FFFFFFF; //infinitely LargeConst intinf=0x3f3f3f3f;/**///**************************************************************************************inline ll read () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}intMA[MAXN][MAXN];intVIS[MAXN];intMATCH[MAXN];intN,m;vector<int>E[MAXN];intDfsinta) { for(intI=0; I<e[a].size (); i++) { if(vis[e[a][i]]==0) {Vis[e[a][i]]=1; if(match[e[a][i]]==-1||DFS (Match[e[a][i])) {Match[e[a][i]]=A; return 1; } } } return 0;}intMain () {intt=read (); while(t--) { intn=read (); memset (Match,-1,sizeof(match)); for(intI=0; i<=n;i++) e[i].clear (); intk=read (); for(intI=0; i<k;i++) { intX=read (), y=read (); E[x].push_back (y); } intcn1=0; for(intI=1; i<=n;i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i) = =1) ans++; } printf ("%d\n", N-ans); }}
HDU 1151 Air Raid Minimum path overlay