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 & Machine Learning] 学习笔记之scikit-learn机器学习库

    1. scikit-learn介绍 scikit-learn是Python的一个开源机器学习模块,它建立在NumPy,SciPy和matplotlib模块之上.值得一提的是,scikit-learn最 ...

  2. IOS系统基础知识

    在iOS应用中,每个程序得main函数中都调用了UIApplicationMain函数. 1 2 3 4 5 6 int main(int argc, char *argv[])  {      @a ...

  3. oracle分区表知识

    在F5中查看执行计划的时候总是看到很多信息: range分区 执行计划中出现的: 分区表,按 n1 ,n2 分区 partition range single:访问单个分区 partition ran ...

  4. PHP函数call_user_func和call_user_func_array详解

    今天在群里面,有个叫lewis的在问call_user_func_array的用法,因为之前一直没有用过,也不能说什么,于是看一下手册,发现是这么写的: call_user_func_array (P ...

  5. PHP中的错误处理、异常处理机制详解

    在编写PHP程序时,错误处理是一个重要的部分.如果程序中缺少错误检测代码,那么看上去很不专业,也为安全风险敞开了大门 例: <?php $a = fopen('test.txt','r'); / ...

  6. 还原MySql数据库失败:max_allowed_packet 设置过小导致记录写入失败

    MySQL根据配置文件会限制Server接受的数据包大小. 有时候大的插入和更新会受 max_allowed_packet 参数限制,导致写入或者更新失败. 查看目前配置 show VARIABLES ...

  7. JavaScript 代码风格指南

    一.基本格式 缩进 建议每级4个空格,可以给编辑器设置tab = 4个空格,自动转换 分号 不要省略分号,防止ASI(自动插入分号)错误 行宽 每行代码不超过80个字符,过长应该用操作符手动断行 断行 ...

  8. Android 组件和进程的一些关系

    1.Service 如果没有单独指定线程的话,那么和主activity是在同一个线程的,就是主线程,那么也不能够在这个service中做耗时操作,否则一定会中断退出. 2.默认情况下,一个Androi ...

  9. opencv的图片的灰度处理‘

    #include "stdafx.h" //实现将彩色图片转换成灰度图 int _tmain(int argc, _TCHAR* argv[]){ IplImage *image; ...

  10. CSS初始化样式

    为什么要初始化CSS? CSS初始化是指重设浏览器的样式.不同的浏览器默认的样式可能不尽相同,所以开发时的第一件事可能就是如何把它们统一.如果没对CSS初始化往往会出现浏览器之间的页面差异.每次新开发 ...