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. 使用python备份指定目录并删除备份超过一定时长的文件

    #!/usr/bin/env python #-*- coding: utf-8 -*- """ @Project:Py @author: @Email: @Softwa ...

  2. Linux系统下安装 rpm 软件和源代码 软件包

    RPM 安装方式 RPM是一个包安装管理软件,我们可以使用这个工具安装 .rpm 类型的软件.Linux的rpm包很多都能在光盘的Packages 包中找得到.首先挂载一下光盘,查看Packages中 ...

  3. [LeetCode] 350. 两个数组的交集 II intersection-of-two-arrays-ii(排序)

    思路: 先找到set的交集,然后分别计算交集中的每个元素在两个原始数组中出现的最小次数. class Solution(object): def intersect(self, nums1, nums ...

  4. webpack实现模块化打包

    webpack打包应用和实现 1)安装webpack $ npm install webpack webpack-cli --save-dev 2)添加配置文件 webpack.config.js 3 ...

  5. DQL命令(查询)

     select *或字段1,字段2...     from 表名     [where 条件]       提示:*符号表示取表中所有列:没有where语句表示        查询表中所有记录:有wh ...

  6. HDU 4321 Contest 3

    题意:给定a和b,n,让你求b+a, b+2*a, .......b+n*a里面有多少1. 当统计第K位的时候 可以注意到 第 B+T*A 和 B+(T+2^(K+1))*A 位是相同的 那么 第K位 ...

  7. Android Material Design-Getting Started(入门)-(一)

    转载请注明出处:http://blog.csdn.net/bbld_/article/details/40400343 翻译自:http://developer.android.com/trainin ...

  8. HDU 2841 Visible Trees(容斥定理)

    Visible Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  9. UI组件之TextView及其子类(一)TextView和EditText

    先来整理一下TexView,EditView的使用方法. Textview是最主要的组件.直接继承了View,也是众多组件的父类.所以了解她的属性会对学习其它组件非常有帮助. TextView的属性: ...

  10. C++之const关键字

    本文引自http://www.cnblogs.com/lichkingct/archive/2009/04/21/1440848.html ,略有增删 const关键字在c++中用法有很多,总结如下: ...