http://poj.org/problem?id=1422

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8579   Accepted: 5129

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

 
最短路径覆盖==总点数-最大匹配数
 #include <cstring>
#include <cstdio> using namespace std; int n,map[][],match[];
bool vis[]; bool find(int u)
{
for(int v=;v<=n;v++)
if(map[u][v]&&!vis[v])
{
vis[v]=;
if(!match[v]||find(match[v]))
{
match[v]=u;
return true;
}
}
return false;
} int AC()
{
int t;scanf("%d",&t);
for(int m,ans;t--;)
{
scanf("%d%d",&n,&m);ans=n;
for(int u,v;m--;map[u][v]=)
scanf("%d%d",&u,&v);
for(int i=;i<=n;i++)
{
memset(vis,,sizeof(vis));
if(find(i)) ans--;
}
printf("%d\n",ans);
memset(map,,sizeof(map));
memset(match,,sizeof(match));
}
return ;
} int I_want_AC=AC();
int main(){;}

POJ——T 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: 6520   Accepted: 3877 Descript ...

  3. poj——1422 Air Raid

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

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

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

  5. POJ 1422 Air Raid

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

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

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

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

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

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

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

  9. POJ Air Raid 【DAG的最小不相交路径覆盖】

    传送门:http://poj.org/problem?id=1422 Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissi ...

随机推荐

  1. linux下静态库的生成和使用

    一.静态库概念 1.库是预编译的目标文件(object  files)的集合,它们可以被链接进程序.静态库以后缀为”.a”的特殊的存档(archive file)存储. 2.标准系统库可在目录/usr ...

  2. HDU 4313 Contest 2

    很明显的树形DP了.但网上有的说可以用并查集.... 考虑一棵子树,当根结点有机器人时,则必定所有子树都要和根结点断开,而根结点向上返回的路径值则为其父结点与根结点连边的权值. 当根结点安全时,假设其 ...

  3. Ruby print

    Ruby print

  4. call to OpenGL ES API with no current context 和Fatal signal 11

    近日在用cocos2dx3.4的时候使用了JNI调用,发现一个现象 当不使用jni的时候全然正常.使用了jni后回去的全部文字都变成黑块,而且有概率程序崩溃.附带出了两个log call to Ope ...

  5. jdk1.8Option类

    目的:为了解决一个方法返回的参数可能为空而无法传入到新的方法做参数的问题,java8产生了新的内容:Option. 定义:Option是一个可以为空的容器对象(注意本质上是个万能对象). 常用方法:1 ...

  6. Sping框架中的注解详解

    传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...

  7. X-射线:探索原子世界的利器

    请看下图: 上图是在现代量子力学意义上的氦(Helium)原子图像,原子像是一个黑乎乎的"小云团"(电子云包围着原子核).原子的半径大约仅仅有1埃. "埃"的符 ...

  8. 判断QString是否为纯数字,查找自身最长重复子字符串

    1.判断QString是否为纯数字 bool IsDigitString(QString strSource) { bool bDigit = false; if (strSource.isEmpty ...

  9. kentico version history and upgrade

    Version history Kentico 10: November 30, 2016 Kentico 9: November 24, 2015 Kentico 8.2: January 6, 2 ...

  10. NOIP卡常数技巧

    NOIP卡常数技巧 https://blog.csdn.net/a1351937368/article/details/78162078 http://www.mamicode.com/info-de ...