*HDU1151 二分图
Air Raid
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4959 Accepted Submission(s): 3339
a town where all the streets are one-way and each street leads from one
intersection to another. It is also known that starting from an
intersection and walking through town's streets you can never reach the
same intersection 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.
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 has the format:
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.
result of the program is on standard output. For each input data set
the program prints on a single line, starting from the beginning of the
line, one integer: the minimum number of paratroopers required to visit
all the intersections in the town.
1
// 模板 有向图最小路径覆盖=n-最大匹配。(用最小的路径覆盖所有的点)
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int mp[][],vis[],link[];
int n,Mu,Mv,m;
int dfs(int x)
{
for(int i=;i<=n;i++)
{
if(!vis[i]&&mp[x][i])
{
vis[i]=;
if(link[i]==-||dfs(link[i]))
{
link[i]=x;
return ;
}
}
}
return ;
}
int Maxcon()
{
int ans=;
memset(link,-,sizeof(link));
for(int i=;i<=n;i++)
{
memset(vis,,sizeof(vis));
if(dfs(i)) ans++;
}
return ans;
}
int main()
{
int t,a,b;
scanf("%d",&t);
while(t--)
{
memset(mp,,sizeof(mp));
scanf("%d%d",&n,&m);
for(int i=;i<m;i++)
{
scanf("%d%d",&a,&b);
mp[a][b]=;
}
Mu=Mv=n;
printf("%d\n",n-Maxcon());
}
return ;
}
*HDU1151 二分图的更多相关文章
- hdu1151 二分图(无回路有向图)的最小路径覆盖 Air Raid
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- hdu1151+poj2594(最小路径覆盖)
传送门:hdu1151 Air Raid 题意:在一个城镇,有m个路口,和n条路,这些路都是单向的,而且路不会形成环,现在要弄一些伞兵去巡查这个城镇,伞兵只能沿着路的方向走,问最少需要多少伞兵才能把所 ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- POJ 2125 Destroying the Graph 二分图最小点权覆盖
Destroying The Graph Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8198 Accepted: 2 ...
- bzoj4025 二分图
支持加边和删边的二分图判定,分治并查集水之(表示我的LCT还很不熟--仅仅停留在极其简单的模板水平). 由于是带权并查集,并且不能路径压缩,所以对权值(到父亲距离的奇偶性)的维护要注意一下. 有一个小 ...
- hdu 1281 二分图最大匹配
对N个可以放棋子的点(X1,Y1),(x2,Y2)......(Xn,Yn);我们把它竖着排看看~(当然X1可以对多个点~) X1 Y1 X2 Y2 X3 Y3 ..... Xn Yn ...
- POJ 2226二分图最大匹配
匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是二部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图 ...
- 二分图&网络流&最小割等问题的总结
二分图基础: 最大匹配:匈牙利算法 最小点覆盖=最大匹配 最小边覆盖=总节点数-最大匹配 最大独立集=点数-最大匹配 网络流: 技巧: 1.拆点为边,即一个点有限制,可将其转化为边 BZOJ1066, ...
- POJ2195 Going Home[费用流|二分图最大权匹配]
Going Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22088 Accepted: 11155 Desc ...
随机推荐
- 入门: 使用JNI 从C++代码中调用Java的静态方法
开发环境: 操作系统: (uname -a output) Linux ubuntu 3.8.0-19-generic #29-Ubuntu SMP Wed Apr 17 18:16:28 UTC ...
- UIScrollView的代理(delegate)
很多时候,我们想在UIScrollView正在滚动 或 滚动到某个位置 或者 停止滚动 时做一些特定的操作 要想完成上述功能,前提条件就是能够监听到UIScrollView的整个滚动过程 当UIScr ...
- Linux进程间通信(四):命名管道 mkfifo()、open()、read()、close()
在前一篇文章—— Linux进程间通信 -- 使用匿名管道 中,我们看到了如何使用匿名管道来在进程之间传递数据,同时也看到了这个方式的一个缺陷,就是这些进程都由一个共同的祖先进程启动,这给我们在不相关 ...
- Nginx 限速模块一览
为了保护服务器不被刷流量,或者业务方面的一些限制,需要做一些限速措施. 一.http 请求并发连接数模块:ngx_http_limit_conn_module 这个模块可以设置每个定义的变量(比如客户 ...
- tomcat不安全因素
tomcat的提供了一个非常方便的manager系统,可以远程上传war项目,运行项目,但是这也是一个非常危险的地方,我曾经开发过一块B/S架构的小系统,提供了本地文件扫描,文件浏览,扫描等功能,并且 ...
- python 字典的函数
clear(),清空 注意单纯的赋值就相当于c语言中引用,只事额外起了一个别名,所以他们指向相同的地址, 所以令c={},只是另外开辟了一个新的空间让c为空,并没有改变之前的空间,所以{}与clear ...
- 最小生成树的Kruskal算法实现
最近在复习数据结构,所以想起了之前做的一个最小生成树算法.用Kruskal算法实现的,结合堆排序可以复习回顾数据结构.现在写出来与大家分享. 最小生成树算法思想:书上说的是在一给定的无向图G = (V ...
- 安装oracle 10g 文件系统
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- Linux命令總結
查看指定端口的監聽 lsof -i tcp:1521
- CS224d assignment 1【Neural Network Basics】
refer to: 机器学习公开课笔记(5):神经网络(Neural Network) CS224d笔记3--神经网络 深度学习与自然语言处理(4)_斯坦福cs224d 大作业测验1与解答 CS224 ...