Treasure Exploration
Time Limit: 6000MS   Memory Limit: 65536K
Total Submissions: 8085   Accepted: 3303

Description

Have you ever read any book about treasure exploration? Have you ever see any film about treasure exploration? Have you ever explored treasure? If you never have such experiences, you would never know what fun treasure exploring brings to you. 
Recently, a company named EUC (Exploring the Unknown Company) plan to explore an unknown place on Mars, which is considered full of treasure. For fast development of technology and bad environment for human beings, EUC sends some robots to explore the treasure. 
To make it easy, we use a graph, which is formed by N points (these N points are numbered from 1 to N), to represent the places to be explored. And some points are connected by one-way road, which means that, through the road, a robot can only move from one end to the other end, but cannot move back. For some unknown reasons, there is no circle in this graph. The robots can be sent to any point from Earth by rockets. After landing, the robot can visit some points through the roads, and it can choose some points, which are on its roads, to explore. You should notice that the roads of two different robots may contain some same point. 
For financial reason, EUC wants to use minimal number of robots to explore all the points on Mars. 
As an ICPCer, who has excellent programming skill, can your help EUC?

Input

The input will consist of several test cases. For each test case, two integers N (1 <= N <= 500) and M (0 <= M <= 5000) are given in the first line, indicating the number of points and the number of one-way roads in the graph respectively. Each of the following M lines contains two different integers A and B, indicating there is a one-way from A to B (0 < A, B <= N). The input is terminated by a single line with two zeros.

Output

For each test of the input, print a line containing the least robots needed.

Sample Input

1 0
2 1
1 2
2 0
0 0

Sample Output

1
1
2 最小路径覆盖。此题点可重,先用floyd求其传递闭包。
最小路径覆盖=点数-最大匹配数
个人感觉有向图和无向图有些许不同,关键在于理解匈牙利算法的过程。(无向图的最大匹配是匈牙利算法求得结果的一半)
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<map>
using namespace std; int mapp[][];
int link[];
int vis[];
int cnt=,m,n; void floyd()
{
for(int k=; k<=n; k++)
for(int i=; i<=n; i++)
{
if(mapp[i][k])
for(int j=; j<n; j++)
if(mapp[k][j])
mapp[i][j]=;
}
} bool dfs(int x)
{
for(int i=; i<=n; i++)
if(mapp[x][i]&&!vis[i])
{
vis[i]=;
if(link[i]==-||dfs(link[i]))
{
link[i]=x;
return true;
}
}
return false;
} int ans;
void solve()
{
memset(link,-,sizeof(link));
for(int i=; i<=n; i++)
{
memset(vis,,sizeof(vis));
if(dfs(i))
ans++;
}
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF&&n+m)
{
memset(mapp,,sizeof(mapp));
for(int i=; i<m; i++)
{
int x,y;
scanf("%d%d",&x,&y);
mapp[x][y]=;
}
floyd();
ans=;
solve();
printf("%d\n",n-ans);
}
return ;
}

POJ_2594_最小路径覆盖的更多相关文章

  1. 【HDU1960】Taxi Cab Scheme(最小路径覆盖)

    Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. loj 1429(可相交的最小路径覆盖)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1429 思路:这道题还是比较麻烦的,对于求有向图的可相交的最小路径覆盖,首先要解决成环问 ...

  3. 【HDU3861 强连通分量缩点+二分图最小路径覆盖】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3861 题目大意:一个有向图,让你按规则划分区域,要求划分的区域数最少. 规则如下:1.有边u到v以及有 ...

  4. POJ 3216 最小路径覆盖+floyd

    Repairing Company Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6646   Accepted: 178 ...

  5. POJ3020Antenna Placement(最小路径覆盖+重在构图)

    Antenna Placement Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7788   Accepted: 3880 ...

  6. POJ 3020 (二分图+最小路径覆盖)

    题目链接:http://poj.org/problem?id=3020 题目大意:读入一张地图.其中地图中圈圈代表可以布置卫星的空地.*号代表要覆盖的建筑物.一个卫星的覆盖范围是其周围上下左右四个点. ...

  7. 【wikioi】1904 最小路径覆盖问题(最大流+坑人的题+最小路径覆盖)

    http://wikioi.com/problem/1904/ 这题没看数据的话是一个大坑(我已报告官方修复了),答案只要求数量,不用打印路径...orz 最小路径覆盖=n-最大匹配,这个我在说二分图 ...

  8. hiho 第118周 网络流四·最小路径覆盖

    描述 国庆期间正是旅游和游玩的高峰期. 小Hi和小Ho的学习小组为了研究课题,决定趁此机会派出若干个调查团去沿途查看一下H市内各个景点的游客情况. H市一共有N个旅游景点(编号1..N),由M条单向游 ...

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

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

随机推荐

  1. 【[Offer收割]编程练习赛13 D】骑士游历(矩阵模板,乘法,加法,乘方)

    [题目链接]:http://hihocoder.com/problemset/problem/1504 [题意] [题解] 可以把二维的坐标转成成一维的; 即(x,y)->(x-1)*8+y 然 ...

  2. elasticsearch 权威指南Mapping(映射)

    什么是映射 类似于数据库中的表结构定义,主要作用如下: 定义Index下字段名(Field Name) 定义字段的类型,比如数值型,字符串型.布尔型等 定义倒排索引的相关配置,比如是否索引.记录pos ...

  3. nyoj_289_苹果_20140307

    苹果 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 ctest有n个苹果,要将它放入容量为v的背包.给出第i个苹果的大小和价钱,求出能放入背包的苹果的总价钱最大值. ...

  4. 洛谷—— P1092 虫食算

    https://www.luogu.org/problem/show?pid=1092 题目描述 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母.来看一个简 ...

  5. Two Heads Are Often Better Than One

    Two Heads Are Often Better Than One Adrian Wible PROGRAMMING REQUIRES DEEP THOUGHT, and deep thought ...

  6. jenkins集成多个项目

    https://www.cnblogs.com/gossip/p/5961376.html 需要jenkins版本高点 安装插件:Multijob plugin

  7. ubuntu下eclipse连接mysql

    提示:一定要保证电脑处于联网状态 我们要下载一个mysql-connector-java-5.0.8-bin.jar的东西(当然这个jar包的版本号和你的mysql版本号的关系不是非常大),放到你新建 ...

  8. 未能加载文件或程序集“System.Web.Helpers, Version=2.0.0.0

    在本地终于用上了ASP.NET MVC4自带的认证功能,但放到生产服务器上就出问题了:打开注册页面没问题,但一点下注册按钮就报错了: 未能加载文件或程序集"System.Web.Helper ...

  9. 虚函数的特点就是执行的时候会下降到子类去执行同名覆盖函数 good

    var t: TBitBtn;begin t:=TBitBtn.Create(nil); t.Name:='BitBtn100'; t.parent :=Self; // 这里下断点end; 一路跟踪 ...

  10. B1041 [HAOI2008]圆上的整点 数学

    这个题一开始看着没什么思路,但是一看题解就明白了不少,主要是数学证明,代码很好写. 贴个网址: hzwer 题干: 题目描述 求一个给定的圆(x^+y^=r^),在圆周上有多少个点的坐标是整数. 输入 ...