POJ 1422 Air Raid
2018-06-17 21:17:38来源:未知 阅读 ()
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8767 | Accepted: 5240 |
Description
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 paratrooper.
Input
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.
Output
Sample Input
2 4 3 3 4 1 3 2 3 3 3 1 3 1 2 2 3
Sample Output
2 1
Source
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> using namespace std; const int MAXN=1001; int vis[MAXN]; int link[MAXN]; int map[MAXN][MAXN]; int N,M; bool dfs(int x) { for(int i=1;i<=N;i++) { if(map[x][i]&&!vis[i]) { vis[i]=1; if(!link[i]||dfs(link[i])) { link[i]=x; return 1; } } } return 0; } struct S { int tall; string a,b,c; }s[MAXN]; int main() { #ifdef WIN32 freopen("a.in","r",stdin); #else #endif int Test; scanf("%d",&Test); while(Test--) { memset(vis,0,sizeof(vis)); memset(link,0,sizeof(link)); memset(map,0,sizeof(map)); scanf("%d%d",&N,&M); for(int i=1;i<=M;i++) { int x,y; scanf("%d%d",&x,&y); map[x][y]=1; } int ans=0; for(int i=1;i<=N;i++) { memset(vis,0,sizeof(vis)); if(dfs(i)) ans++; } printf("%d\n",N-ans ); } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- POJ-3278 2020-04-01
- Asteroids!_poj2225 2020-02-09
- poj-1753题题解思路 2020-01-26
- POJ1852 2019-11-11
- POJ2431 优先队列+贪心 - biaobiao88 2019-11-03
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash