hdoj--1151--Air Raid(最大独立集)
Air Raid
i.e. the town's streets form no cycles.
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.
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.
in the town.
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
2
1
#include<stdio.h>
#include<math.h>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std;
vector<int>map[200];
int used[200],pipei[200];
int find(int x)
{
for(int i=0;i<map[x].size();i++)
{
int y=map[x][i];
if(!used[y])
{
used[y]=1;
if(!pipei[y]||find(pipei[y]))
{
pipei[y]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
memset(pipei,0,sizeof(pipei));
for(int i=1;i<=n;i++)
map[i].clear();
for(int i=0;i<m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
map[x].push_back(y);
}
int sum=0;
for(int i=1;i<=n;i++)
{
memset(used,0,sizeof(used));
sum+=find(i);
}
printf("%d\n",n-sum);
}
return 0;
}
hdoj--1151--Air Raid(最大独立集)的更多相关文章
- HDOJ 1151 Air Raid
最小点覆盖 Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- hdu 1151 Air Raid(二分图最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
- hdu 1150 Machine Schedule hdu 1151 Air Raid 匈牙利模版
//两道大水……哦不 两道结论题 结论:二部图的最小覆盖数=二部图的最大匹配数 有向图的最小覆盖数=节点数-二部图的最大匹配数 //hdu 1150 #include<cstdio> #i ...
- hdu 1151 Air Raid DAG最小边覆盖 最大二分匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151 题目大意: 城镇之间互相有边,但都是单向的,并且不会构成环,现在派伞兵降落去遍历城镇,问最少最少 ...
- hdu 1151 Air Raid - 二分匹配
Consider a town where all the streets are one-way and each street leads from one intersection to ano ...
- hdu - 1151 Air Raid(有向无环图的最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 在一个城市里有n个地点和k条道路,道路都是单向的,并且不存在环.(DAG) 现在伞兵需要去n个地点视察,伞 ...
- (step6.3.4)hdu 1151(Air Raid——最小路径覆盖)
题意: 一个镇里所有的路都是单向路且不会组成回路. 派一些伞兵去那个镇里,要到达所有的路口,有一些或者没有伞兵可以不去那些路口,只要其他人能完成这个任务.每个在一个路口着陆了的伞兵可以沿着街去 ...
- HDU 1151 Air Raid(最小路径覆盖)
题目大意: 有n个城市,m条道路,城市的道路是单向. 现在我们的伞兵要降落在城市里,然后我门的伞兵要搜索所有道路.问我们最少占领多少个城市就可以搜索所有的道路了. 我们可以沿着道路向前走到达另一个城 ...
- HDU 1151 - Air Raid
很明显求最小路径覆盖 就是求最大匹配 #include <iostream> #include <cstdio> #include <cstring> #inclu ...
- hdu 1151 Air Raid 最小路径覆盖
题意:一个城镇有n个路口,m条路.每条路单向,且路无环.现在派遣伞兵去巡逻所有路口,伞兵只能沿着路走,且每个伞兵经过的路口不重合.求最少派遣的伞兵数量. 建图之后的就转化成邮箱无环图的最小路径覆盖问题 ...
随机推荐
- Jquery 获取父页面下指定iframe里的指定元素
var div1=$("#iframe1",window.parent.document).contents().find("#div1");
- Java创建Excel-DEMO
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.Out ...
- 前端Canvas思维导图笔记
看不清的朋友右键保存或者新窗口打开哦!喜欢我可以关注我,还有更多前端思维导图笔记
- AI:PR的数学表示-传统方法PR
前言: 接上一篇:AI:模式识别的数学表示 在图像处理PR领域,相对于ANN方法,其他的方法一般称为传统方法.在结构上,几乎所有的PR方法都是可解释的.且任一传统方法,在一定约束下,可以转换为SV近邻 ...
- ROS:使用ubuntuKylin17.04安装ROS赤xi龟
使用ubuntuKylin17.04安装 参考了此篇文章:SLAM: Ubuntu16.04安装ROS-kinetic 重复官方链接的步骤也没有成功. 此后发现4.10的内核,不能使用Kinetic. ...
- Linux下Shell脚本输出带颜色文字
文本终端的颜色可以使用“ANSI非常规字符序列”来生成.举例: echo -e "\033[44;37;5m ME \033[0m COOL" 以上命令设置作用如下: 背景色为蓝色 ...
- Robot Framework(八) 资源和变量文件
2.7资源和变量文件 测试用例文件和测试套件初始化文件中的用户关键字和变量只能在创建它们的文件中使用,但资源文件提供了共享它们的机制.由于资源文件结构非常接近测试用例文件,因此很容易创建它们. 变量文 ...
- 【转载】JSTL 标签大全详解
版权声明:本文为博主原创文章,转载请注明出处,冷血之心的博客. https://blog.csdn.net/qq_25827845/article/details/53311722 (尊重劳动成果,转 ...
- Lua操作系统库、流、文件库
Lua操作系统库.流.文件库 1.Lua中所有的操作系统库函数 (1)os.clock() --功能:返回执行该程序cpu花费的时钟秒数 (2)os.time(...) --按参数的内容返回一个时间值 ...
- [Usaco2004 Open]Cube Stacking 方块游戏
题面: 约翰和贝茜在玩一个方块游戏.编号为1到n的n(1≤n≤30000)个方块正放在地上.每个构成一个立方柱. 游戏开始后,约翰会给贝茜发出P(1≤P≤100000)个指令.指令有两种 ...