Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 8006   Accepted: 4803

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

最小路径覆盖。匈牙利算法。

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int T,n,m;
int mp[mxn][mxn];
int link[mxn];
bool vis[mxn];
bool find(int u){
for(int i=;i<=n;i++){
if(mp[u][i] && !vis[i]){
vis[i]=;
if(link[i]==- || find(link[i])){
link[i]=u;
return ;
}
}
}
return ;
}
int solve(){
int res=;
for(int i=;i<=n;i++){
memset(vis,,sizeof vis);
if(find(i))res++;
}
return res;
}
int main(){
T=read();
int i,j,u,v;
while(T--){
memset(mp,,sizeof mp);
memset(link,-,sizeof link);
n=read();m=read();
for(i=;i<=m;i++){
u=read();v=read();
mp[u][v]=;
}
int res=solve();
printf("%d\n",n-res);
}
return ;
}

POJ1422 Air Raid的更多相关文章

  1. POJ1422 Air Raid 【DAG最小路径覆盖】

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

  2. POJ1422 Air Raid 和 CH6902 Vani和Cl2捉迷藏

    Air Raid Language:Default Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 9547 A ...

  3. Air Raid[HDU1151]

    Air RaidTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  4. hdu1151 二分图(无回路有向图)的最小路径覆盖 Air Raid

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  5. 【网络流24题----03】Air Raid最小路径覆盖

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

  6. hdu-----(1151)Air Raid(最小覆盖路径)

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

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

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

  8. HDOJ 1151 Air Raid

    最小点覆盖 Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

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

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7511   Accepted: 4471 Descript ...

随机推荐

  1. AJPFX总结JAVA基本数据类型

    1:关键字(掌握)        (1)被Java语言赋予特定含义的单词        (2)特点:                全部小写.        (3)注意事项:              ...

  2. iOS programming UITableView and UITableViewController

    iOS programming  UITableView and UITableViewController A UITableView displays a single column of dat ...

  3. .net mvc 运行监控和错误捕捉

    方法类 /// <summary> /// 运行监控类 /// </summary> [AttributeUsage(AttributeTargets.Class | Attr ...

  4. postgresql update from

    1,update   from   关联表的更新 update table a set name=b.name from table B b  where a.id=b.id; update test ...

  5. win7电脑桌面壁纸曝光过高影响图标怎么办?亲测实用解决方法

    现在用win7系统的人应该还是挺多的吧,虽然说windows家族已经升级到现在的win11了,相信大多数人家用的电脑系统还是win7吧,今天要讲的是一个壁纸曝光度过高的解决办法,虽然还不清楚为什么,但 ...

  6. js添加千位分隔符

    function thousandBitSeparator(num){ var re=/\d{1,3}(?=(\d{3})+$)/g; var n1=num.toString().replace(/^ ...

  7. Android(java)学习笔记194:ContentProvider使用之获得系统联系人信息02(掌握)

    1.重要: 系统删除一个联系人,默认情况下并不是把这个联系人直接删除掉了,只是做了一个标记,标记为被删除. 2.前面一讲说过了如何获取系统联系人信息(通过ContentProvider),获取联系人信 ...

  8. list.extend的结果是None

    执行list.exend()方法后,会直接修改list本身,而不会产生返回值 In [97]: d=(43,) In [98]: type(d) Out[98]: tuple In [99]: c O ...

  9. java网络编程_IP地址

    InetAddress类,此类表示Internet协议(IP)地址.具体使用方法查看文档:https://docs.oracle.com/en/java/javase/11/docs/api/java ...

  10. Java基础(十二)--clone()方法

    Clone在Java中就是用来复制对象,通过分配一个和源对象相同大小的内存空间,然后创建一个新的对象,那么他和=的区别在哪? 通过=实现对象拷贝: @Data @NoArgsConstructor @ ...