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. Spring Boot JPA中java 8 的应用

    文章目录 Optional Stream API CompletableFuture Spring Boot JPA中java 8 的应用 上篇文章中我们讲到了如何在Spring Boot中使用JPA ...

  2. Element UI表格组件技巧:如何简洁实现跨页勾选、跨页统计功能

    业务场景 在使用Element UI的Table组件时,常常面对这样的业务需求: 表格数据的每一项都要提供勾选框,当切换分页时,能够记忆所有页面勾选的数据,以实现批量提交不同页面勾选数据的功能.并且, ...

  3. Spark 源码系列(六)Shuffle 的过程解析

    Spark 大会上,所有的演讲嘉宾都认为 shuffle 是最影响性能的地方,但是又无可奈何.之前去百度面试 hadoop 的时候,也被问到了这个问题,直接回答了不知道. 这篇文章主要是沿着下面几个问 ...

  4. javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

    2019独角兽企业重金招聘Python工程师标准>>> 问题 前两天一个学弟在群里面问一个问题: 请问一下用阿里云服务器发送https请求为什么会失败,是需要有些其他什么配置吗? 同 ...

  5. python(写入 excel 操作 xlwt 模块)

    一.安装 xlwt 模块 pip install xlwt 二.excel 写入操作 这种方式只能新增或者覆盖文件写入 import xlwt # 创建一个workbook 设置编码 workbook ...

  6. go 模板详说

    模板是我们常用的手段用于动态生成页面,或者用于代码生成器的编写等.比如把数据库的表映射成go语言的struct,这些体力活,写个代码生成器是最合适不过的了. 示例例把表转成 struct : 当然这篇 ...

  7. Java——Java面向对象

    该系列博文会告诉你如何从入门到进阶,一步步地学习Java基础知识,并上手进行实战,接着了解每个Java知识点背后的实现原理,更完整地了解整个Java技术体系,形成自己的知识框架. 概述: Java是面 ...

  8. 多重背包转化成完全背包 E - Charlie's Change

    http://poj.org/problem?id=1787 这个题目我一看就觉得是一个多重背包,但是呢,我不知道怎么输出路径,所以无可奈何,我就只能看一下题解了. 看了题解发现居然是把多重背包转化成 ...

  9. Spring官网阅读(九)Spring中Bean的生命周期(上)

    文章目录 生命周期回调 1.Bean初始化回调 2.Bean销毁回调 3.配置默认的初始化及销毁方法 4.执行顺序 5.容器启动或停止回调 Lifecycle 接口 LifecycleProcesso ...

  10. puamap是什么意思

    artists map 定义格式:[puamap代号 名] 相关属性: 1.FIGHT 2.SAFE 安全区域 3.DARK 4.NEEDHOLE 配合mapinfo里 x,y -> x1,y1 ...