Air Raid

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4959    Accepted Submission(s): 3339

Problem Description
Consider
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.

 
Input
Your
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.

 
Output
The
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.
 
Sample Input
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
 
Sample Output
2
1
 
Source
 
题意:
n个路口,m条单向路,无环,求 最小路径覆盖。
代码:
 // 模板 有向图最小路径覆盖=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 二分图的更多相关文章

  1. hdu1151 二分图(无回路有向图)的最小路径覆盖 Air Raid

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  2. hdu1151+poj2594(最小路径覆盖)

    传送门:hdu1151 Air Raid 题意:在一个城镇,有m个路口,和n条路,这些路都是单向的,而且路不会形成环,现在要弄一些伞兵去巡查这个城镇,伞兵只能沿着路的方向走,问最少需要多少伞兵才能把所 ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  5. bzoj4025 二分图

    支持加边和删边的二分图判定,分治并查集水之(表示我的LCT还很不熟--仅仅停留在极其简单的模板水平). 由于是带权并查集,并且不能路径压缩,所以对权值(到父亲距离的奇偶性)的维护要注意一下. 有一个小 ...

  6. hdu 1281 二分图最大匹配

    对N个可以放棋子的点(X1,Y1),(x2,Y2)......(Xn,Yn);我们把它竖着排看看~(当然X1可以对多个点~) X1   Y1 X2   Y2 X3   Y3 ..... Xn   Yn ...

  7. POJ 2226二分图最大匹配

    匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是二部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图 ...

  8. 二分图&网络流&最小割等问题的总结

    二分图基础: 最大匹配:匈牙利算法 最小点覆盖=最大匹配 最小边覆盖=总节点数-最大匹配 最大独立集=点数-最大匹配 网络流: 技巧: 1.拆点为边,即一个点有限制,可将其转化为边 BZOJ1066, ...

  9. POJ2195 Going Home[费用流|二分图最大权匹配]

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22088   Accepted: 11155 Desc ...

随机推荐

  1. Python正则表达式详解

    我用双手成就你的梦想 python正则表达式 ^ 匹配开始 $ 匹配行尾 . 匹配出换行符以外的任何单个字符,使用-m选项允许其匹配换行符也是如此 [...] 匹配括号内任何当个字符(也有或的意思) ...

  2. nginx error_log 错误日志配置说明

    nginx的error_log类型如下(从左到右:debug最详细 crit最少): [ debug | info | notice | warn | error | crit ] 例如:error_ ...

  3. FixFFmpeg 修改官方编译的ffmpeg能在 XP 上运行的工具

    把 fixff.cmd 和 FixFFmpeg.exe 拷贝到 ffmpeg 所在的目录 运行 fixff.cmd 自动修复; fixffmpeg-20160924.7z

  4. opendrive

    opendrive和其他许多网盘一样.注册拥有5G的免费空间.每天1G的免费外链流量.更重要的是,他能够给你提供一个直接外链!这是国内外许多网盘都没有的.当你上载了一个MP3,你想用直接外链的形式在博 ...

  5. position:fixed 属性在iphone 中不起作用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. NPOI导出EXCEL 打印设置分页及打印标题

    在用NPOI导出EXCEL的时候设置分页,在网上有查到用sheet1.SetRowBreak(i)方法,但一直都没有起到作用.经过研究是要设置  sheet1.FitToPage = false; 而 ...

  7. .NET 获取类型中的属性

    解决方案      通过反射的方式获取类型中的所有属性. 引用命名空间 using System.Reflection; 实体类 public class User { private string ...

  8. RAD Studio 2009-10Seattle IDE Fix Pack 5.94

    IDE Fix Pack 5.94 IDE Fix Pack is a collection of unofficial bug fixes and performance optimizations ...

  9. monkey工具使用中遇到的问题之一:手机模拟器中的部分应用出现网络无法连接

    问题描述: 手机模拟器中的部分应用出现网络无法连接,但是比如:浏览器即可以正常访问网页 解决方法如下: 1.以管理员身份进入到cmd中,以WIN10为例 ,在电脑左下角点击鼠标右键就可以看到 注意: ...

  10. 简单快捷好用的vim配置和终端配置推荐

    vim 配置实用spf13-vim,安装方便简单快捷,极力推荐. 另外oh-my-zsh 终端配置很好,与之搭配使用效果更佳. 安装都很简单,一个脚本搞定, 都是在gitHub上开源的,自行搜索,这里 ...