BNUOJ 1541 Air Raid
Air Raid
This problem will be judged on PKU. Original ID: 1422
64-bit integer IO format: %lld Java class name: Main
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
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
Sample Input
2
4
3
3 4
1 3
2 3
3
3
1 3
1 2
2 3
Sample Output
2
1
Source
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
int mp[maxn][maxn],from[maxn],n,m;
bool vis[maxn];
bool dfs(int u){
for(int v = ; v <= n; v++){
if(mp[u][v] && !vis[v]){
vis[v] = true;
if(from[v] == - || dfs(from[v])){
from[v] = u;
return true;
}
}
}
return false;
}
int main() {
int t,u,v,ans,i;
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
memset(mp,,sizeof(mp));
memset(from,-,sizeof(from));
for(i = ; i < m; i++){
scanf("%d %d",&u,&v);
mp[u][v] = ;
}
ans = ;
for(i = ; i <= n; i++){
memset(vis,false,sizeof(vis));
if(dfs(i)) ans++;
}
printf("%d\n",n-ans);
}
return ;
}
BNUOJ 1541 Air Raid的更多相关文章
- Air Raid[HDU1151]
Air RaidTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- hdu1151 二分图(无回路有向图)的最小路径覆盖 Air Raid
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- 【网络流24题----03】Air Raid最小路径覆盖
Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- hdu-----(1151)Air Raid(最小覆盖路径)
Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- hdu 1151 Air Raid(二分图最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
- HDOJ 1151 Air Raid
最小点覆盖 Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Air Raid(最小路径覆盖)
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7511 Accepted: 4471 Descript ...
- POJ1422 Air Raid 【DAG最小路径覆盖】
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6763 Accepted: 4034 Descript ...
- POJ 1422 Air Raid(二分图匹配最小路径覆盖)
POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...
随机推荐
- Linux环境下SolrCloud集群环境搭建关键步骤
Linux环境下SolrCloud集群环境搭建关键步骤. 前提条件:已经完成ZooKeeper集群环境搭建. 一.下载介质 官网下载地址:http://www.apache.org/dyn/close ...
- 递归查找无效的符号链接 分类: linux c/c++ 2014-06-02 00:14 345人阅读 评论(0) 收藏
本程序实现在指定目录下递归查找无效的符号链接. 1.设计思路 逐个读取给定目录中的目录项,判断类型 (1)若为目录,则读取该目录中的目录项并判断类型: (2)若为链接文件,则读取出其指向文件的名称(绝 ...
- mysql 中 时间函数 now() current_timestamp() 和 sysdate() 比较
转载请注明出处 https://www.cnblogs.com/majianming/p/9647786.html 在mysql中有三个时间函数用来获取当前的时间,分别是now().current_t ...
- IO流的原理和概念
在程序中如何读写文件?不同的编程语言有不同的方式,而 JAVA 则提出了“流”的概念,通过“流”来读写文件 什么是流: 流(Stream)是指一连串的数据(字符或字节),是以先进先出的方式发送信息的通 ...
- iOS 画环形图
由于新项目的的需求,需要画环形图,由于以前都没接触过这一类(我是菜鸟),去cocochina山找到了一个案例,个人觉得还可以,分享一下 github 地址https://github.com/zhou ...
- [BZOJ1009][HNOI2008]GT考试 DP+矩阵快速幂+KMP
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1009 我们令$dp(i,j)$表示已经填了$i$位,而且后缀与不幸运数字匹配了$j$位,那 ...
- 11 DOM基础
1.css 标签 js 元素 dom 节点,元素节点,属性节点,文本节点 2.dom浏览器支持率 ie 10% chrome 60% FF 99% 3. ...
- GIS在石油行业中的应用
在石油工业中,发现新的石油资源,取得竞争优势,是成功的关键之一.GIS系统能帮助评估潜在的石油资源,及时.准确.直观地定位油气资源的空间分布及其特征,以正确有效地开展部署勘探开发工作,占领市场先机. ...
- Farseer.net轻量级开源框架 中级篇:探究ORM(Mapping)
导航 目 录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 中级篇: SQL执行报告 下一篇:Farseer.net轻量级开源框架 中级篇: Cooki ...
- php常用的一些代码
1.获取用户真实ip function getIP() { if (getenv("HTTP_X_FORWARDED_FOR")) { // 这个提到最前面,作为优先级,nginx ...