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. Java基础学习总结(69)——匿名内部类与Lambda表达式

    前言 Java Labmda表达式的一个重要用法是简化某些匿名内部类(Anonymous Classes)的写法.实际上Lambda表达式并不仅仅是匿名内部类的语法糖,JVM内部是通过invokedy ...

  2. qwb与小数

    qwb与小数 Time Limit: 1 Sec  Memory Limit: 128 MB Description qwb遇到了一个问题:将分数a/b化为小数后,小数点后第n位的数字是多少? 做了那 ...

  3. Spring MVC-表单(Form)标签-列表框(Listbox)示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_listbox.htm 说明:示例基于Spring MVC 4.1.6. 以下示例 ...

  4. [学习笔记—Objective-C]《Objective-C-基础教程 第2版》第二章~第七章

    在看完<Objective-C 程序设计 第6版>之后,看了一些关于iOS开发职位的面试题,发现自身基础非常是不牢,于是打算以查缺补漏的方式阅读还有一本关于Objective-C的基础书籍 ...

  5. java Regex

    超全 http://www.rexegg.com/regex-lookarounds.html 这篇文章不错:http://www.cnblogs.com/lzq198754/p/5780340.ht ...

  6. 微信 创建自定义菜单 向微信发起的post请求

    微信 创建自定义菜单 向微信发起的post请求 Map<String, Object> res = new HashMap<String, Object>(); try { S ...

  7. 基数排序之多keyword排序运用队列

    源码例如以下: #include <stdlib.h> #include <stdio.h> typedef struct QUEUEnode* link; struct QU ...

  8. 关于Android开发数据存储的方式(一)

    关于Android开发数据存储方式(一) 在厦门做Android开发也有两个月了,快情人节了.我还在弄代码. 在微信平台上开发自己的APP,用到了数据存储的知识,如今总结一下: 整体的来讲.数据存储方 ...

  9. [字典树] poj 2418 Hardwood Species

    题目链接: id=2418">http://poj.org/problem?id=2418 Hardwood Species Time Limit: 10000MS   Memory ...

  10. 尝试create tech team

    自从上一家公司之后,我很少有机会去带一些新人(公司一般都招一些技术独立性的工程师),特别是经验不是特别多的新小伙伴.在如今管理扁平化的公司,我正逐渐搭建自己的小team,并试图让团队成员快速融入并成长 ...