Air Raid
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 7278   Accepted: 4318

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

 
 
题目意思:
给一n个点m条边的有向图(无环),求最少多少条路径能把所有点覆盖。
 
思路:
最小路径覆盖。ans=n-最大匹配数。
 
代码:
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
using namespace std; #define N 205 int max(int x,int y){return x>y?x:y;}
int min(int x,int y){return x<y?x:y;}
int abs(int x,int y){return x<?-x:x;} int n, m;
bool visited[N];
vector<int>ve[N];
int from[N]; int march(int u){
int i, j, k, v;
for(i=;i<ve[u].size();i++){
v=ve[u][i];
if(!visited[v]){
visited[v]=true;
if(from[v]==-||march(from[v])){
from[v]=u;
return ;
}
}
}
return ;
} main()
{
int t, i, j, k;
int u, v;
cin>>t;
while(t--){ scanf("%d %d",&n,&m);
for(i=;i<=n;i++) ve[i].clear();
for(i=;i<m;i++){
scanf("%d %d",&u,&v);
ve[u].push_back(v);
}
memset(from,-,sizeof(from));
int num=;
for(i=;i<=n;i++){
memset(visited,false,sizeof(visited));
if(march(i)) num++;
}
printf("%d\n",n-num);
}
}

最新文章

  1. remove ---会报错discard不会报错
  2. $.extend()的用法【转】
  3. asp.net 学习
  4. SQLServer2008:助您轻松编写T-SQL存储过程(原创)【转】
  5. springmvc中forward和redirect
  6. 几种sap增强的查找方法
  7. laydate时间组件在火狐浏览器下有多时间输入框时只能给第一个输入框赋值的问题
  8. PHP的抽象类和接口
  9. Hadoop-2.7.1集群环境搭建
  10. DML
  11. 基于visual Studio2013解决C语言竞赛题之1040因数分解
  12. [置顶] Android事件—单选按键和下拉按键
  13. 为什么delphi控件前面都有t
  14. Java设计模式——观察者模式
  15. sql 查询结果转百分比
  16. dubbo入门学习 四 注册中心 zookeeper入门
  17. MySQL数据库报错pymysql.err.InterfaceError: (0, &#39;&#39;)
  18. linux常用命令:mv 命令
  19. 从客户端(SeekingJobs=&quot;&lt;B&gt;&#183;&lt;/B&gt; 物流规划,&lt;B&gt;&#183;&lt;/...&quot;)中检测到有潜在危险的 Request.Form 值。
  20. SonarQube学习入门指南

热门文章

  1. 百度之星复赛Astar Round3
  2. xml配置文件详解
  3. html5实现GIF动画!
  4. 【Todo】Python字符编码学习
  5. Android控件_TextView(显示文本框控件)
  6. Sqlserver_insert语法
  7. SQL语句在数据库中是如何执行的
  8. Linux命令行下编译Android NDK的示例代码
  9. innodb_fast_shutdown中值为1或者2的区别是?
  10. 学习ASP.NET之前,先了解它