POJ——T 1422 Air Raid
http://poj.org/problem?id=1422
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 8579 | Accepted: 5129 |
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 <cstring>
#include <cstdio> using namespace std; int n,map[][],match[];
bool vis[]; bool find(int u)
{
for(int v=;v<=n;v++)
if(map[u][v]&&!vis[v])
{
vis[v]=;
if(!match[v]||find(match[v]))
{
match[v]=u;
return true;
}
}
return false;
} int AC()
{
int t;scanf("%d",&t);
for(int m,ans;t--;)
{
scanf("%d%d",&n,&m);ans=n;
for(int u,v;m--;map[u][v]=)
scanf("%d%d",&u,&v);
for(int i=;i<=n;i++)
{
memset(vis,,sizeof(vis));
if(find(i)) ans--;
}
printf("%d\n",ans);
memset(map,,sizeof(map));
memset(match,,sizeof(match));
}
return ;
} int I_want_AC=AC();
int main(){;}
POJ——T 1422 Air Raid的更多相关文章
- POJ 1422 Air Raid(二分图匹配最小路径覆盖)
POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...
- poj 1422 Air Raid (二分匹配)
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6520 Accepted: 3877 Descript ...
- poj——1422 Air Raid
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8577 Accepted: 5127 Descript ...
- poj 1422 Air Raid 最少路径覆盖
题目链接:http://poj.org/problem?id=1422 Consider a town where all the streets are one-way and each stree ...
- POJ 1422 Air Raid
题目链接: http://poj.org/problem?id=1422 Description Consider a town where all the streets are one-way a ...
- POJ 1422 Air Raid (最小路径覆盖)
题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...
- POJ - 1422 Air Raid 二分图最大匹配
题目大意:有n个点,m条单向线段.如今问要从几个点出发才干遍历到全部的点 解题思路:二分图最大匹配,仅仅要一条匹配,就表示两个点联通,两个点联通仅仅须要选取当中一个点就可以,所以有多少条匹配.就能够减 ...
- POJ - 1422 Air Raid(DAG的最小路径覆盖数)
1.一个有向无环图(DAG),M个点,K条有向边,求DAG的最小路径覆盖数 2.DAG的最小路径覆盖数=DAG图中的节点数-相应二分图中的最大匹配数 3. /* 顶点编号从0开始的 邻接矩阵(匈牙利算 ...
- POJ Air Raid 【DAG的最小不相交路径覆盖】
传送门:http://poj.org/problem?id=1422 Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
随机推荐
- nefu 84 ( 拓展欧几里德模板题 )
链接:传送门 思路:拓展欧几里德模板题,设大圣至少翻转 t 次,大圣起始位置为 x ,大圣目标位置为 y + n * s ( 大圣到达目标位置 y 可能需要多圈,所以用 s 来表示圈数 ),因为只能逆 ...
- POJ 2356 Find a multiple( 鸽巢定理简单题 )
链接:传送门 题意:题意与3370类似 注意:注意输出就ok,输出的是集合的值不是集合下标 /***************************************************** ...
- freeswitch GUI界面(portal)
1.控制台 加载模块 load mod_xml_rpc 2.ip:8080/portal 进行登录 账号 : freeswitch 密码 : works 让模块随着freeswitch启动进行加载 ...
- Python 绘图与可视化 matplotlib(下)
详细的参考链接:更详细的:https://www.cnblogs.com/zhizhan/p/5615947.html 图像.子图.坐标轴以及记号 Matplotlib中图像的意思是打开的整个画图窗口 ...
- .net 参数修饰符
参数修饰符的作用 参数修饰符 作用 无 如果一个参数没有用参数修饰符标记,则认为它将按值传递(pass by value),这意味着被调用的方法收到原始数据的一份副本 out 输出参数由被调用的方法赋 ...
- Mysql学习总结(31)——MySql使用建议,尽量避免这些问题
做服务器端开发的同学们,相信对于mysql应该是十分熟悉,但是一旦真正出现问题,你是否能够快速的发现问题的起因,并且解决呢?一旦问题涉及到数据库层面,往往不是那么好解决的,通常来说,我们需要提前做应对 ...
- 使用Modernizr检测支持CSS3
使用Modernizr检测支持CSS3 如果支持某个属性,会增加一个class,名字就是该属性: 不支持,名字是no-某属性 还提供了一个全局Modernizr对象,使用如下: <script ...
- 同一个TextView设置不同的颜色和大小
//strategy1是一个TextView SpannableStringBuilder builder1 = new SpannableStringBuilder(strategy1.getTex ...
- Codeforces Round #286 (Div. 1) B. Mr. Kitayuta's Technology (强连通分量)
题目地址:http://codeforces.com/contest/506/problem/B 先用强连通判环.然后转化成无向图,找无向图连通块.若一个有n个点的块内有强连通环,那么须要n条边.即正 ...
- HDU 1040.As Easy As A+B【排序】【如题(水!水!水!)】【8月24】
As Easy As A+B Problem Description These days, I am thinking about a question, how can I get a probl ...