点击打开链接题目链接

Treasure Exploration
Time Limit: 6000MS   Memory Limit: 65536K
Total Submissions: 7215   Accepted: 2947

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

某条路径能够反复走多次

用floyed求出能够到达的点

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 555
using namespace std;
int n,m;
bool g[MAXN][MAXN];
bool vis[MAXN];
int link[MAXN];
void init(){
memset(vis,0,sizeof(vis));
memset(link,-1,sizeof(link));
memset(g,0,sizeof(g));
}
void floyed(){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(g[i][j]==0){
for(int k=0;k<n;k++){
if(g[i][k]&&g[k][j]){
g[i][j]=1;
break;
}
}
}
}
}
}
bool finds(int x){
for(int i=0;i<n;i++){
if(!vis[i]&&g[x][i]){
vis[i]=1;
if(link[i]==-1||finds(link[i])){
link[i]=x;
return 1;
}
}
}
return 0;
}
int main(){
while(scanf("%d %d",&n,&m)&&(n||m)){
init();
int st,ed;
for(int i=1;i<=m;i++){
scanf("%d %d",&st,&ed);
st--;
ed--;
g[st][ed]=1;
}
floyed();
int ans=0;
for(int i=0;i<n;i++){
memset(vis,0,sizeof(vis));
if(finds(i))
ans++;
}
printf("%d\n",n-ans);
}
}

poj 2594 Treasure Exploration 二分图匹配的更多相关文章

  1. poj 2594 Treasure Exploration (二分匹配)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 6558   Accepted: 2 ...

  2. POJ 2594 Treasure Exploration(最小路径覆盖变形)

    POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要 ...

  3. Poj 2594 Treasure Exploration (最小边覆盖+传递闭包)

    题目链接: Poj 2594 Treasure Exploration 题目描述: 在外星上有n个点需要机器人去探险,有m条单向路径.问至少需要几个机器人才能遍历完所有的点,一个点可以被多个机器人经过 ...

  4. poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)

    http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total ...

  5. POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】

    Treasure Exploration Time Limit:6000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64 ...

  6. POJ 2594 Treasure Exploration 最小可相交路径覆盖

    最小路径覆盖 DAG的最小可相交路径覆盖: 算法:先用floyd求出原图的传递闭包,即如果a到b有路径,那么就加边a->b.然后就转化成了最小不相交路径覆盖问题. 这里解释一下floyd的作用如 ...

  7. POJ 2594 Treasure Exploration (可相交最小路径覆盖)

    题意 给你张无环有向图,问至少多少条路径能够覆盖该图的所有顶点--并且,这些路径可以有交叉. 思路 不是裸的最小路径覆盖,正常的最小路径覆盖中两个人走的路径不能有重复的点,而本题可以重复. 当然我们仍 ...

  8. poj 2594 Treasure Exploration(最小路径覆盖,可重点)

    题意:选出最小路径覆盖图中所有点,路径可以交叉,也就是允许路径有重复的点. 分析:这个题的难点在于如何解决有重复点的问题-方法就是使用Floyd求闭包,就是把间接相连的点直接连上边,然后就是求最小路径 ...

  9. POJ 2594 Treasure Exploration(带交叉路的最小路径覆盖)

    题意:  派机器人去火星寻宝,给出一个无环的有向图,机器人可以降落在任何一个点上,再沿着路去其他点探索,我们的任务是计算至少派多少机器人就可以访问到所有的点.有的点可以重复去. 输入数据: 首先是n和 ...

随机推荐

  1. 解决iOS空指针数据的问题

    iOS开发中常常会遇到空指针的问题. 如从后台传回来的Json数据,程序中不做推断就直接赋值操作,非常有可能出现崩溃闪退. 为了解决空指针的问题,治标的方法就是遇到一个处理一个.这样业务代码里面就插了 ...

  2. elasticsearch 源码概述

    从功能上说,可以分为两部分,分布式功能和数据功能.分布式功能主要是节点集群及集群附属功能如restful借口.集群性能检测功能等,数据功能主要是索引和搜索.代码上这些功能并不是完全独立,而是由相互交叉 ...

  3. RGB颜色转换为多种颜色工具、公式

    http://www.easyrgb.com/index.php?X=CALC#Result http://www.easyrgb.com/index.php?X=MATH  

  4. 14. Spring Boot MyBatis 连接数据库

    转自:https://blog.csdn.net/catoop/article/details/50553714

  5. 通过量产解决U盘写保护,无法格式化问题

    1.首先下载ChipGenius.地址:http://pan.baidu.com/s/1eQvf1zc 2.解压,双击ChipGenius_v4_00_0027_pre2. 3.能够检測到U盘的主控厂 ...

  6. android 登录和设置IP/端口功能

    本人第一个Android开发功能:登录以及设置IP/端口. 本人是j2ee开发工程师,所以这个可能有一些处理不太完善的地方,欢迎评论在下面,我会认真改进的. 首先是配置strings.xml文件添加用 ...

  7. C语言深度剖析-----数组与指针分析

    数组的本质: 指针的运算: 小标VS指针: a和&a的区别: 例: 数组参数: 所以下例返回4 指针和数组的对比小结:

  8. python中如何在一张图上画两条折线

    摘自:https://segmentfault.com/q/1010000002760775

  9. 【Codeforces Round #437 (Div. 2) B】Save the problem!

    [链接]h在这里写链接 [题意]     给你一个金额N,和硬币的类型总数M;     (完全背包),然后问你组成N的方案数.     使得,用这些硬币组成价值为N的金额的方案数为A;     现在A ...

  10. DBeaver笔记-快捷键篇

    公司使用的是PostgreSQL数据库,可以使用pgAdmin或者DBeaver进行连接该数据库.个人更喜欢用DBeaver,因为其界面更加美观,操作也相对简单.对于习惯了eclipse的开发者来说, ...