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 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...
随机推荐
- 自定义View(11)**在onDraw中使用矩阵Matrix
1.代码示例 1.1 效果 原图 : 其尺寸为162 x 251,示例中的红点是变形的锚点. 变形之后: 1.2 代码 package com.e.weixin.session.view; impor ...
- ATM机(非函数版)
#include<stdio.h>#include<stdlib.h>int main(void){char zhangHao[]="123";int mi ...
- h5学习-webstorm工具的激活
这里有个快速激活webstorm的方法:http://jingyan.baidu.com/article/9f63fb919674f2c8400f0e9a.html h5的轮廓工具:https://g ...
- Spring注解驱动开发之Ioc容器篇
前言:现今SpringBoot.SpringCloud技术非常火热,作为Spring之上的框架,他们大量使用到了Spring的一些底层注解.原理,比如@Conditional.@Import.@Ena ...
- poj1930 Dead Fraction
思路: 循环小数化分数,枚举所有可能的循环节,取分母最小的那个. 实现: #include <iostream> #include <cstdio> #include < ...
- CCF|最小差值|Java
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = ...
- Android 计算view 的高度
上午在做一个QuickAction里嵌套一个ListView,在Demo运行没事,结果引入到我的项目里,发现我先让它在Button上面,结果是无视那个Button的高度,这很明显,就是那个Button ...
- POJ_1125_(dijkstra)
Stockbroker Grapevine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35553 Accepted: ...
- swift 即使不使用oc的动态派发机制也应该借鉴isa类型识别机制
目前的消息派发机制真的很鸡肋. 简直是一堆狗屎. 类型信息中包含所有需要动态派发的函数:这个包含两类:类和protocol: 在编译时,首先搜索动态派发列表: 动态派发列表没有,在搜索静态派发列表: ...
- shell脚本的练习
创建一个以.sh结束的文件. 规则: 文件的头部使用#!/bin/sh 开头 这个是一个标识的作用,告诉使用哪种脚本来执行 echo 用来向命令行来输出的东西