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

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

对于DAG,求最小路径覆盖有例如以下公式:最小路径覆盖数 = 节点数 - 相应的二分图最大匹配数。

用电脑自带的绘图画了张草图,挫爆了 -_-!


题意:输入数据具体解释,t组数据。n个节点(从1開始)。m条有向边。u到v。

题解:套公式。

#include <stdio.h>
#include <string.h> const int maxn = 125;
int n, m;
int cx[maxn], cy[maxn];
bool visy[maxn], G[maxn][maxn]; void getMap() {
memset(G, 0, sizeof(G));
int u, v;
scanf("%d%d", &n, &m);
while(m--) {
scanf("%d%d", &u, &v);
G[u][v] = true;
}
} int findPath(int x) {
int i;
for(i = 1; i <= n; ++i) {
if(G[x][i] && !visy[i]) {
visy[i] = 1;
if(cy[i] == -1 || findPath(cy[i])) {
cy[i] = x; return 1;
}
}
}
return 0;
} int MaxMatch() {
int ans = 0, i;
memset(cx, -1, sizeof(cx));
memset(cy, -1, sizeof(cy));
for(i = 1; i <= n; ++i) {
memset(visy, 0, sizeof(visy));
if(cx[i] == -1) ans += findPath(i);
}
return ans;
} void solve() {
printf("%d\n", n - MaxMatch());
} int main() {
// freopen("stdin.txt", "r", stdin);
int t;
scanf("%d", &t);
while(t--) {
getMap();
solve();
}
return 0;
}

POJ1422 Air Raid 【DAG最小路径覆盖】的更多相关文章

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

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

  2. HDU - 1151 Air Raid (最小路径覆盖)

    题意:给定一个有向无环图,求最少划分几条路径,使之能够覆盖所有点. 分析:这可以转化为DAG上的最小路径覆盖问题. 路径覆盖的定义:有向图中,路径覆盖就是在图中找一些路径,使之覆盖了图中的所有顶点,且 ...

  3. HDU 1151 Air Raid(最小路径覆盖)

    题目大意: 有n个城市,m条道路,城市的道路是单向.  现在我们的伞兵要降落在城市里,然后我门的伞兵要搜索所有道路.问我们最少占领多少个城市就可以搜索所有的道路了. 我们可以沿着道路向前走到达另一个城 ...

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

    Description Consider a town where all the streets are one-way and each street leads from one interse ...

  5. uva1201 DAG 最小路径覆盖,转化为 二分图

    大白例题P356 你在一座城市里负责一个大型活动的接待工作.你需要去送m个人从出发地到目的地,已知每个人的出发时间出发地点,和目的地点,你的任务是用尽量少的出租车送他们,使得每次出租车接客人,至少能提 ...

  6. 【LA3126 训练指南】出租车 【DAG最小路径覆盖】

    题意 你在一座城市里负责一个大型活动的接待工作.明天将有m位客人从城市的不同的位置出发,到达他们各自的目的地.已知每个人的出发时间,出发地点和目的地.你的任务是用尽量少的出租车送他们,使得每次出租车接 ...

  7. 训练指南 UVALive - 3126(DAG最小路径覆盖)

    layout: post title: 训练指南 UVALive - 3126(DAG最小路径覆盖) author: "luowentaoaa" catalog: true mat ...

  8. 1350 Taxi Cab Scheme DAG最小路径覆盖

    对于什么是DAG最小路径覆盖以及解题方法在我的另外的博客已经有了.http://www.cnblogs.com/Potato-lover/p/3980470.html 此题的题意: 公交车(出租车)车 ...

  9. hdu3861 The King’s Problem 强连通缩点+DAG最小路径覆盖

    对多校赛的题目,我深感无力.题目看不懂,英语是能懂的,题目具体的要求以及需要怎么做没有头绪.样例怎么来的都不明白.好吧,看题解吧. http://www.cnblogs.com/kane0526/ar ...

随机推荐

  1. ListBox控件

    主要介绍:自定义数据.绑定数据库数据 前台代码: <div> <asp:ListBox ID=" Width ="100px"> <asp: ...

  2. 合并k个已排序的链表 分类: leetcode 算法 2015-07-09 17:43 3人阅读 评论(0) 收藏

    最先想到的是把两个linked lists 合并成一个. 这样从第一个开始一个一个吞并,直到所有list都被合并. class ListNode:# Definition for singly-lin ...

  3. 极光IM使用教程-极光推送

    链接地址:http://jingyan.baidu.com/article/a948d65178a6ea0a2ccd2e7e.html 极光IM使用教程,如果您的 App 需要同时集成 Push 功能 ...

  4. 学习linux能有什么用

    很多朋友装了 Linux,看着全新的菜单样式.陌生的程序,一下子脑袋就空了(特别是系统未安装中文语言支持时),不知该干点什么,于是一种强烈的想法涌上心头——还是先回瘟到死玩一会儿游戏再说吧~ 在这,我 ...

  5. java设计模式之——策略模式

    1.策略模式有什么好处? 策略模式的好处在于你可以动态的改变对象的行为. 2.设计原则 设计原则是把一个类中经常改变或者将来可能改变的部分提取出来,作为一个接口(c++中可以用虚类),然后在类中包含这 ...

  6. c++ 静态成员遇到的坑总结

    新标签页http://74.55.154.136/ c++ 静态成员遇到的坑总结 - linuxfloat - 博客园 c++ 静态成员遇到的坑总结   1.对于类静态变量的初始化,用下面方法. // ...

  7. <Win32_18>平滑的人物走动 —— 解决闪屏

    今天咋一看,发现很久没写博客了 的确,开学之后,写博客的时间越来越少了…… 今天来做一个比较实用的小应用——平滑的人物走动,同时解决常见的闪屏问题.实现透明位图 这些技术在游戏开发中是很常见的 --- ...

  8. Android使用学习之画图(Canvas,Paint)与手势感应及其应用(乒乓球小游戏)

    作为一个没有学习Android的菜鸟,近期一直在工作之外努力地学习的Android的使用. 这周看了下Android的画图.主要是Canvas,Paint等,感觉须要实践下.下午正好有空,就想整一个乒 ...

  9. linux 下vi中关于删除某段,某行,或者全部删除的命令

    1,先打开某个文件: vi   filename 2,转到文件结尾 在命令模式输入 G       转到10行 在命令模式输入 10G 4,删除所有内容:先用G 转到文件尾,然后使用下面命令: :1, ...

  10. 在 Visual Studio 调试器中指定符号 (.pdb) 和源文件

    查找并指定符号文件和源文件:指定符号加载行为.使用符号和源服务器上:加载符号自动或在要求.   内容 查找符号 (.pdb) 文件 查找源文件   查找符号 (.pdb) 文件 说明 在之前的 Vis ...