Air Raid

Time Limit: 1000ms
Memory Limit: 10000KB

This problem will be judged on PKU. Original ID: 1422
64-bit integer IO format: %lld      Java class name: Main

 
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

 
解题:最小路径覆盖。。。
 
路径覆盖是什么?一个PXP的有向图中,路径覆盖就是在图中找一些路径,使之覆盖了图中的所有顶点,且任何一个顶点有且只有一条路径与之关联;(如果把这些路径中的每条路径从它的起始点走到它的终点,那么恰好可以经过图中的每个顶点一次且仅一次);如果不考虑图中存在回路,那么每条路径就是一个弱连通子集.
 
最小路径覆盖=|P|-最大匹配数
 
 #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的更多相关文章

  1. Air Raid[HDU1151]

    Air RaidTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

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

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

  3. 【网络流24题----03】Air Raid最小路径覆盖

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  4. hdu-----(1151)Air Raid(最小覆盖路径)

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. hdu 1151 Air Raid(二分图最小路径覆盖)

    http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS   Memory Limit: 10000K To ...

  6. HDOJ 1151 Air Raid

    最小点覆盖 Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  7. Air Raid(最小路径覆盖)

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7511   Accepted: 4471 Descript ...

  8. POJ1422 Air Raid 【DAG最小路径覆盖】

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6763   Accepted: 4034 Descript ...

  9. POJ 1422 Air Raid(二分图匹配最小路径覆盖)

    POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...

随机推荐

  1. 题解报告:hdu 1754 I Hate It(线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1754 Problem Description 很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某 ...

  2. [C#基础知识系列]专题十:全面解析可空类型[转]

    原文链接 主要内容: 1:空合并操作符(?? 操作符) ??操作符也就是"空合并操作符",它代表的意思是两个操作数,如果左边的数不为null时,就返回左边的数,如果左边的数为nul ...

  3. lavas安装

    最近在研究pwa,百度基于此写了一套开源框架lavas,学习下: 1.环境准备: lavas 安装.git安装 Node.js:https://nodejs.org/ Git:https://git- ...

  4. 2016/10/29 Action类中execute方法的使用

    第一步:先配置web.xml文件 <filter> <filter-name>struts2</filter-name> <filter-class>o ...

  5. ambari-server启动WARN qtp-ambari-client-87] ServletHandler: 563 /api/v1/stacks/HDP/versions/2.4/recommendations java.lang.NullPointerException报错解决办法(图文详解)

      问题详情 来源是,我在Ambari集群里,安装Hue. 给Ambari集群里安装可视化分析利器工具Hue步骤(图文详解 所遇到的这个问题. 然后,去ambari-server的log日志,查看,如 ...

  6. 前端--1、HTML基础

    web服务 处于应用层的http协议负责的数据传输与解析.位于socket上层,用socket传输http数据时需要在消息开头处声明是http协议/相应http版本 状态码 状态码含义 \r\n\r\ ...

  7. 萌新--关于vue.js入门及环境搭建

    十几天闭关修炼,恶补了html跟css以及JavaScript相应的基础知识,恰巧有个群友准备做开源项目,愿意带着我做,但是要求我必须懂vue.js,所以开始恶补vue.js相关的东西. 在淘宝上买了 ...

  8. Java数据类型和MySql数据类型对应一览 [转]

    类型名称 显示长度 数据库类型 JAVA类型 JDBC类型索引(int) 描述             VARCHAR L+N VARCHAR java.lang.String 12   CHAR N ...

  9. 最实用解决tomcat startup.bat 一闪而过

    1.直接到tomcat 的解压路径中找到log日志,eg:D:\tomcat\apache-tomcat-7.0.73\logs 查看 catalina 这个日志文件,可以清除的定位错误原因:一般可能 ...

  10. Net作业调度

    Net作业调度(一) -Quartz.Net入门 2014-11-01 13:14 by 蘑菇先生, 13954 阅读, 7 评论, 收藏, 编辑 背景 很多时候,项目需要在不同时刻,执行一个或很多个 ...