*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 ...
随机推荐
- VTK初学一,vtkDelaunay2D创建球冠曲面
#ifndef INITIAL_OPENGL #define INITIAL_OPENGL #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRend ...
- css 强制 中文、英文 换行
.livechat-text a { display: block; word-break:break-all; /* 英文换行 */ white-space:normal; /* 中文换行 */ } ...
- BZOJ3436——小K的农场
1.题意:大概是给一些制约限制,问是否存在合法解 2.分析:我们来观察这三个限制 农场a比农场b至少多种植了c个单位的作物 可以变成b 比 a至多多种了-c 农场a比农场b至多多种植了c个单位 ...
- 上个项目的一些反思 I
最近一直在反思之前的项目,发现了很多问题.比如数据安全... 虽然项目需求是只展示最新的数据,所以几乎没用什么本地存储.除了通讯录和用户的Token. 用户通讯录另表,今天反思下用户的Token的存储 ...
- python匹配ip正则
python匹配ip正则 #!/usr/bin/env python # -*- coding:utf-8 -*- import re ip_str = "asdad1.1.1.1sdfwe ...
- [转]Struts2工作原理
Struts2请求响应流程: 在struts2的应用中,从用户请求到服务器返回相应响应给用户端的过程中,包含了许多组件如:Controller.ActionProxy.ActionMapping.Co ...
- NHibernate简单使用介绍
1.在数据库中新建表格,并插入记录,SQL如下: USE WFC_DB GO create table Students ( Id ,) not null, Name ), Age int, Scor ...
- 没有活动事务 链接服务器的 OLE DB 访问接口 "SQLNCLI" 无法启动分布式事务
在windows2003下执行分布式事务的时候出现如下情况. 一. 问题现象在执行分布式事务时,在sql server 2005下收到如下错误: 链接服务器"xxxxxxx"的 O ...
- C++ 判断字符串是否全是数字
在实际的工作中,需要提取程序中的字符串信息,但是程序中经常将一些数字当做字符串来进行处理,例如表盘的刻度信息,这时候就需要判断字符串是否全为数字,来进行真正意义上的字符串提取.下面介绍了判断字符串是否 ...
- 万全R630服务器组装RAID5阵列
随笔, 昨天领导让我给一台服务器做系统,本身作为开发的我有一些挑战.而且领导说的事,怎么着也得努努力试试不是? 下午去机房找到服务器本以为仅仅是装个系统完事,而且据我了解服务器本身有系统,以为拿着系统 ...