Air Raid
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 6520   Accepted: 3877

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

  1. 2
  2. 4
  3. 3
  4. 3 4
  5. 1 3
  6. 2 3
  7. 3
  8. 3
  9. 1 3
  10. 1 2
  11. 2 3

Sample Output

  1. 2
  2. 1

Source

 
最大边覆盖=原点数-最大匹配
  1. //152K 0MS C++ 965B 2014-06-03 12:26:21
  2. #include<iostream>
  3. #include<vector>
  4. #define N 205
  5. using namespace std;
  6. vector<int>V[N];
  7. int vis[N];
  8. int match[N];
  9. int n;
  10. int dfs(int u)
  11. {
  12. for(int i=;i<V[u].size();i++){
  13. int v=V[u][i];
  14. if(!vis[v]){
  15. vis[v]=;
  16. if(match[v]==- || dfs(match[v])){
  17. match[v]=u;
  18. return ;
  19. }
  20. }
  21. }
  22. return ;
  23. }
  24. int hungary()
  25. {
  26. memset(match,-,sizeof(match));
  27. int ret=;
  28. for(int i=;i<=n;i++){
  29. memset(vis,,sizeof(vis));
  30. ret+=dfs(i);
  31. }
  32. return ret;
  33. }
  34. int main(void)
  35. {
  36. int t,m,a,b;
  37. scanf("%d",&t);
  38. while(t--)
  39. {
  40. scanf("%d",&n);
  41. for(int i=;i<=n;i++) V[i].clear();
  42. scanf("%d",&m);
  43. while(m--){
  44. scanf("%d%d",&a,&b);
  45. V[a].push_back(b);
  46. //V[b].push_back(a);
  47. }
  48. printf("%d\n",n-hungary());
  49. }
  50. return ;
  51. }
 

poj 1422 Air Raid (二分匹配)的更多相关文章

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

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

  2. poj——1422 Air Raid

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8577   Accepted: 5127 Descript ...

  3. poj 1422 Air Raid 最少路径覆盖

    题目链接:http://poj.org/problem?id=1422 Consider a town where all the streets are one-way and each stree ...

  4. POJ 1422 Air Raid

    题目链接: http://poj.org/problem?id=1422 Description Consider a town where all the streets are one-way a ...

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

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

  6. POJ - 1422 Air Raid 二分图最大匹配

    题目大意:有n个点,m条单向线段.如今问要从几个点出发才干遍历到全部的点 解题思路:二分图最大匹配,仅仅要一条匹配,就表示两个点联通,两个点联通仅仅须要选取当中一个点就可以,所以有多少条匹配.就能够减 ...

  7. POJ - 1422 Air Raid(DAG的最小路径覆盖数)

    1.一个有向无环图(DAG),M个点,K条有向边,求DAG的最小路径覆盖数 2.DAG的最小路径覆盖数=DAG图中的节点数-相应二分图中的最大匹配数 3. /* 顶点编号从0开始的 邻接矩阵(匈牙利算 ...

  8. hdu1151 Air Raid 二分匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151 求最小路径覆盖 二分图最小路径覆盖=点的个数-最大匹配. 代码: #include<ios ...

  9. hdu 1151 Air Raid - 二分匹配

    Consider a town where all the streets are one-way and each street leads from one intersection to ano ...

随机推荐

  1. 北京Uber优步司机奖励政策(11月23日~11月29日)

    用户组:人民优步"关羽组"(适用于11月23日-11月29日)奖励政策: 滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最 ...

  2. P1094 纪念品分组

    P1094 纪念品分组 题目描述 元旦快到了,校学生会让乐乐负责新年晚会的纪念品发放工作.为使得参加晚会的同学所获得 的纪念品价值相对均衡,他要把购来的纪念品根据价格进行分组,但每组最多只能包括两件纪 ...

  3. JDK1.8改为JDK1.7过程

    电脑之前eclipse版本要求JDK1.8版本,现在要用jboss7.1做性能测试,目前仅支持JDK7.故需要降级. 网上有很多说把1.8删掉,这种做法我是不建议的,那么要用的时候呢?又得装回来多蛋疼 ...

  4. Date 工具类(包含常用的一些时间方法)

    package com.fh.util; import java.sql.Timestamp; import java.text.DateFormat; import java.text.ParseE ...

  5. mysql 开启远程连接

    如图,修改mysql数据库中user表中的User字段为root的host为%,然后重新启动mysql服务即可让远程桌面连接本地.

  6. Qt-网络与通信-获取本机网络信息

    在网络应用中,经常需要获取本机主机名和IP地址和硬件地址等信息.运用QHostInfo.QNetworkInterface.QNetworkAddressEntry可以获得本机的网络信息. 上运行截图 ...

  7. Selenium(Python)生成Html测试报告

    由于Python3已经不支持HTMLTestRunner了, 无论是PyCharm还是pip都无法安装成功, 所以只能去 http://tungwaiyip.info/software/HTMLTes ...

  8. JVM监控远程服务器

    1. 首先配置服务器端,进入服务器tomcat的bin目录下,打开catalina.sh配置文件,xxx为服务器配置路径. # cd /xxx/apache-tomcat-/bin # vim cat ...

  9. lesson 24 A skeleton in the cupboard

    lesson 24 A skeleton in the cupboard conceal sth from sb 对某人隐藏某事 He conceals his girlfriend from his ...

  10. TPO-10 C2 Return a literature book

    TPO-10 C2 Return a literature book 第 1 段 1.Listen to a conversation between a student and an employe ...