Treasure Exploration
Time Limit: 6000MS   Memory Limit: 65536K
Total Submissions: 8909   Accepted: 3644

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

Source

与一般最小路径的区别就是这个点可以属于两个及以上不同的路径之中

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
const int M=3e5+;
bool mp[N][N],vis[N];
int used[N],head[N],tot,n;
struct node
{
int to,next;
} e[M];
void add(int u,int v){
e[tot].to=v;e[tot].next=head[u];head[u]=tot++;
}
bool findx(int u)
{
for(int i=head[u]; ~i; i=e[i].next)
{
int v=e[i].to;
if(vis[v]) continue;
vis[v]=;
if(!used[v]||findx(used[v]))
{
used[v]=u;
return true;
}
}
return false;
}
void floyd()
{
for(int i=; i<=n; ++i) for(int j=; j<=n; ++j) for(int k=; k<=n; ++k)
mp[i][j]=mp[i][j]|(mp[i][k]&&mp[k][j]);
}
int main()
{
int m,x,y;
while(scanf("%d%d",&n,&m),n||m)
{
tot=;
memset(mp,,sizeof(mp));
memset(used,,sizeof(used));
memset(head,-,sizeof(head));
while(m--)
{
scanf("%d%d",&x,&y);
mp[x][y]=;
}
floyd();
int maxmatch=;
for(int i=; i<=n; ++i) for(int j=; j<=n; ++j) if(mp[i][j]) add(i,j);
for(int i=; i<=n; ++i)
{
memset(vis,,sizeof(vis));
if(findx(i)) ++maxmatch;
}
printf("%d\n",n-maxmatch);
}
}

poj2594最小路径覆盖+floyd的更多相关文章

  1. poj2594 (最小路径覆盖 + floyd)

    题目链接  http://poj.org/problem?id=2594) 题目大意: 一个有向图中, 有若干条连接的路线, 问最少放多少个机器人,可以将整个图上的点都走过. 最小路径覆盖问题. 分析 ...

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

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

  3. poj2594——最小路径覆盖

    Description Have you ever read any book about treasure exploration? Have you ever see any film about ...

  4. POJ2594 最小路径覆盖

    题意:       题意就是给你个有向无环图,问你最少放多少个机器人能把图全部遍历,机器人不能走回头路线. 思路:      如果直接建图,跑一遍二分匹配输出n - 最大匹配数会跪,原因是这个题目和以 ...

  5. POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 9794   Accepted: 3 ...

  6. POJ-2594 Treasure Exploration,floyd+最小路径覆盖!

                                                 Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...

  7. POJ-2594 Treasure Exploration floyd传递闭包+最小路径覆盖,nice!

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8130   Accepted: 3 ...

  8. HDU 4606 Occupy Cities ★(线段相交+二分+Floyd+最小路径覆盖)

    题意 有n个城市,m个边界线,p名士兵.现在士兵要按一定顺序攻占城市,但从一个城市到另一个城市的过程中不能穿过边界线.士兵有一个容量为K的背包装粮食,士兵到达一个城市可以选择攻占城市或者只是路过,如果 ...

  9. hdu 4606 简单计算几何+floyd+最小路径覆盖

    思路:将所有的直线的两个端点和城市混在一起,将能直接到达的两个点连线,求一次floyd最短路径.二分枚举bag容量,然后按给的要先后占领的城市由前向后,把能到一步到达的建一条边.然后求一次最小路径覆盖 ...

随机推荐

  1. Struts2漏洞利用

    Struts漏洞合集 Struts-S2-013漏洞利用 受影响版本 Struts 2.0.0 - Struts 2.3.14.1 漏洞利用 任意命令执行POC: ${(#_memberAccess[ ...

  2. 标准SQL语句大全【持续更新】(navicat12版亲测有效)

    提示:用ctrl+F快速查找相关指令哦 -- 创建数据库 create database test_sql; -- 修改数据库名称(只有 sysadmin 和 dbcreator 固定服务器角色的成员 ...

  3. 【Linux网络基础】TCP/IP协议簇的详细介绍(三次握手四次断开,11种状态)

    一.TCP/IP协议簇(DoD参考模型) 用于简化OSI层次,以及相关的标准. 传输控制协议(tcp/ip)簇是相关国防部DoD所创建的,主要用来确保数据的完整性以及在毁灭性战争中维持通信 是由一组不 ...

  4. 15.Why lambda forms in python does not have statements?

    Why lambda forms in python does not have statements? A lambda form in python does not have statement ...

  5. 关于利用注射点判断数据库web是否分离

    得到客户端主机名:select host_name();得到服务端主机名: select @@servername; 本文转hackfreer51CTO博客,原文链接:http://blog.51ct ...

  6. Android FrameWork学习(二)Android系统源码调试

    通过上一篇 Android FrameWork学习(一)Android 7.0系统源码下载\编译 我们了解了如何进行系统源码的下载和编译工作. 为了更进一步地学习跟研究 Android 系统源码,今天 ...

  7. Gitlab常规操作

    一.Git和SVN的区别 和SVN类似,Git是一个版本控制系统(Version Control System,VCS),不同的是SVN为集中式版本控制系统,为单一的集中管理的服务器,保存所有文件的修 ...

  8. Spring Boot学习 之 Spring Boot Actuator(一)

    Spring Boot版本:2.1.4.RELEASE 启用: spring-boot-actuator模块提供了一系列的用于监控的端点.最简单的开启这个功能的方法就是,在pom文件中添加如下的依赖. ...

  9. Unity2019.3缺少Cinemachine插件/AssetStore搜索不到

    Unity2019.1版本都还自带Cinemachine,到2019.3就没有了(原因暂时未知),PackageManager里没有,到资源商店里搜索也找不到 解决方法: Windows>Pac ...

  10. MongoDB最佳安全实践

    在前文[15分钟从零开始搭建支持10w+用户的生产环境(二)]中提了一句MongoDB的安全,有小伙伴留心了,在公众号后台问.所以今天专门开个文,写一下关于MongoDB的安全. 一.我的一次Mong ...