点击打开题目链接

Air Raid

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5289    Accepted Submission(s): 3547

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
Asia 2002, Dhaka (Bengal)
Recommend
Ignatius.L   |   We have carefully selected several similar problems for you:  1281 1507 1528 1498 1054 

Statistic | Submit | Discuss | Note

题目大意:有一个城镇有n个路口和m条路,分配伞兵去守这些路口,每个伞兵只能沿着路的方向走,问最少需要多少伞兵可以把所有路巡查一遍。

思路:有向无环图求最小路径覆盖问题。有向无环图的最小路径覆盖=所有顶点-最大匹配数

匈牙利算法

附上AC代码:

#include<iostream>
#include<cstring>using namespace std;
const int maxn=120+5;
int G[maxn][maxn];
int used[maxn];
int result[maxn];
int T;
int numint,numstr;
int cnt;
int a,b;
//寻找增广路
int find(int x)
{for(int i=1;i<=numint;i++){if(G[x][i]==1&&!used[i]){used[i]=1;if(result[i]==-1||find(result[i])){result[i]=x;return 1;}}}return 0;
}
int main()
{ios::sync_with_stdio(false);cin>>T;while(T--){memset(result,-1,sizeof(result));memset(G,0,sizeof(G));cnt=0;cin>>numint>>numstr;for(int i=0;i<numstr;i++){cin>>a>>b;G[a][b]=1;//建立有向边}for(int i=1;i<=numint;i++){memset(used,0,sizeof(used));//每次初始化标记if(find(i))cnt++;}cout<<numint-cnt<<endl;}return 0;
}

HDU- 1151 Air Raid(最小路径覆盖)相关推荐

  1. HDU - 1151 Air Raid(最小路径覆盖-二分图最大匹配)

    题目链接:点击查看 题目大意:给出一个有向图,现在需要在不同的地方空降伞兵,保证所有伞兵沿着道路可以走完所有城市,求出最少伞兵的数量 题目分析:我们的目的是要用最少的路径覆盖所有顶点,换句话说就是二分 ...

  2. (hdu step 6.3.3)Air Raid(最小路径覆盖:求用最少边把全部的顶点都覆盖)

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

  3. POJ 1422 Air Raid (最小路径覆盖)

    题意 给定一个有向图,在这个图上的某些点上放伞兵,可以使伞兵可以走到图上所有的点.且每个点只被一个伞兵走一次.问至少放多少伞兵. 思路 裸的最小路径覆盖. °最小路径覆盖 [路径覆盖]在一个有向图G( ...

  4. HDU 1151 Air Raid

    DAG的最小路径覆盖 #include<stdio.h> #include<iostream> #include<algorithm> #include<st ...

  5. 有向图最小路径覆盖方法浅析、证明 //hdu 3861

    路径覆盖就是在图中找一些路径,使之覆盖了图中的所有顶点,且任何一个顶点有且只有一条路径与之关联. 对于一个有向无环图怎么求最小路径覆盖? 先构造二分图: 对于原图,先拆点,吧每个点i拆成ii,iii. ...

  6. HDU 3861 The King’s Problem (强连通缩点+DAG最小路径覆盖)

    <题目链接> 题目大意: 一个有向图,让你按规则划分区域,要求划分的区域数最少. 规则如下:1.所有点只能属于一块区域:2,如果两点相互可达,则这两点必然要属于同一区域:3,区域内任意两点 ...

  7. HDU 3861 The King’s Problem 强连通分量 最小路径覆盖

    先找出强连通分量缩点,然后就是最小路径覆盖. 构造一个二分图,把每个点\(i\)拆成两个点\(X_i,Y_i\). 对于原图中的边\(u \to v\),在二分图添加一条边\(X_u \to Y_v\ ...

  8. hdu 4160 (Dolls)二分图的最小路径覆盖

    关于二分图,让人很头疼啊!归结为一句话,就是看不出来题目是二分图的问题. 也许是对二分图不太熟悉吧!需要多练习! 题目大意:给出n个箱子,每个箱子的参数为长,宽,高:(a,b,c):当且仅当箱子s1, ...

  9. The King’s Problem(tarjan求强连通分量缩点+匈牙利求有向无环图的最小路径覆盖)

    Link:http://acm.hdu.edu.cn/showproblem.php?pid=3861 The King's Problem Time Limit: 2000/1000 MS (Jav ...

  10. 【网络流24题】最小路径覆盖问题

    [题目]1738: 最小路径覆盖问题 [题解]网络流 关于输出路径,因为即使有反向弧经过左侧点也一定会改变左侧点的去向,若没连向右侧就会被更新到0,所以不用在意. mark记录有入度的右侧点,然后从没 ...

最新文章

  1. Active Directory之Sysvol的修复、移动及重建
  2. Linux Shell 逻辑运算符、逻辑表达式详解
  3. linux jsp mysql数据库,Linux JSP连接MySQL数据库.pdf
  4. DCMTK:读取DICOM图像,添加一个Curve并将其写回
  5. ServiceStack.Redis之IRedisClient第三篇
  6. 使用dom4j解析XML文件
  7. 七秘诀工作效率与薪水翻番
  8. Java集合框架面试题总结及解析
  9. JAVA电子书大礼包
  10. 施耐德 m340 编程手册_PLC模拟量的通用转换原理以及编程方法
  11. tomcat8下载安装教程
  12. drf之day09:内置的认证类,权限类,频率类,django配置文件解析,过滤类的其他作用,全局异常处理,接口文档
  13. 酒店PMS变革之路:开放互联、模块化配置
  14. android网络编程-socket基础
  15. 信息系统项目管理师必背核心考点(六十三)项目组合管理的主要过程DIPP分析
  16. cbac式_abca式的成语
  17. doc命令大全(经典收藏)
  18. Nature | 奇病毒(Mirusviruses)将疱疹病毒与巨型病毒联系起来
  19. 面试测试开发工程师:用例篇
  20. 页面图片轮播完整代码

热门文章

  1. 你的宽带ip地址被100.64了吗?
  2. Spanning-tree guard features配置案例
  3. 背包问题(简单回溯)
  4. TCP非持久连接、持久性连接(流水线方式、非流水线方式)例题
  5. linux开发员用游戏本吗,为什么很多程序员使用thinkpad而不是同等价位的游戏本呢?...
  6. LeetCode——线段树
  7. VGA和HDMI传输距离是否有要求?
  8. wireshark-filter帮助手册
  9. 前端架构师的YY定义
  10. 阿里巴巴达摩院夺得首届“马栏山杯”国际音视频算法优化大赛【画质损伤修复赛道】冠军