题目链接:http://poj.org/problem?id=2594

Treasure Exploration
Time Limit: 6000MS   Memory Limit: 65536K
Total Submissions:10480   Accepted: 4250

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.
题目大意:给出一张有向图,求最小多少个机器人可以经过所有的点。
思路:
1.因为是可重复经过点的,所以路径是可相交的。求最小路径覆盖 = 原图顶点数 - 新图最大匹配数。
2.对于可相交的最小路径覆盖问题,要先用 floyd 求一下传递闭包。转化为不可相交的最小路径覆盖来求。
代码如下:
 #include<stdio.h>
#include<string.h>
#define mem(a, b) memset(a, b, sizeof(a))
const int MAXN = ;
const int MAXM = ; int n, m; //n个点 m条有向边
int line[MAXN][MAXN], used[MAXN], master[MAXN]; void floyd()
{
for(int i = ; i <= n; i ++)
for(int j = ; j <= n; j ++)
for(int k = ; k <= n; k ++)
if(line[i][k] && line[k][j])
line[i][j] = ;
} int find(int x)
{
for(int i = ; i <= n; i ++) //y部的点
{
if(line[x][i] && used[i] == -)
{
used[i] = ;
if(master[i] == - || find(master[i]))
{
master[i] = x;
return ;
}
}
}
return ;
} int main()
{
while(scanf("%d%d", &n, &m) != EOF)
{
if(n == && m == )
break;
int cnt = ;
mem(line, ), mem(master, -);
for(int i = ; i <= m; i ++)
{
int a, b;
scanf("%d%d", &a, &b);
line[a][b] = ;
}
floyd();
for(int i = ; i <= n; i ++) //x部的点
{
mem(used, -);
if(find(i))
cnt ++; //最大匹配数
}
printf("%d\n", n - cnt);
}
return ;
}

POJ2594 Treasure Exploration【DAG有向图可相交的最小路径覆盖】的更多相关文章

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

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

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

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

  3. POJ2594 Treasure Exploration[DAG的最小可相交路径覆盖]

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

  4. Treasure Exploration POJ - 2594 【有向图路径可相交的最小路径覆盖】模板题

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

  5. poj 2594(可相交的最小路径覆盖)

    题目链接:http://poj.org/problem?id=2594 思路:本来求最小路径覆盖是不能相交的,那么对于那些本来就可达的点怎么处理,我们可以求一次传递闭包,相当于是加边,这样我们就可以来 ...

  6. poj 2594Treasure Exploration(有向图路径可相交的最小路径覆盖)

    1 #include<iostream> #include<cstring> #include<algorithm> #include<cstdio> ...

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

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

  8. 【LA3126 训练指南】出租车 【DAG最小路径覆盖】

    题意 你在一座城市里负责一个大型活动的接待工作.明天将有m位客人从城市的不同的位置出发,到达他们各自的目的地.已知每个人的出发时间,出发地点和目的地.你的任务是用尽量少的出租车送他们,使得每次出租车接 ...

  9. Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配

    /** 题目:Taxi Cab Scheme UVALive - 3126 最小路径覆盖解法(必须是DAG,有向无环图) = 结点数-最大匹配 链接:https://vjudge.net/proble ...

随机推荐

  1. 031_检测 MySQL 服务是否存活

    #!/bin/bash#host 为你需要检测的 MySQL 主机的 IP 地址,user 为 MySQL 账户名,passwd 为密码#这些信息需要根据实际情况修改后方可使用 host=127.0. ...

  2. python ros 设置机器人的位置

    #!/usr/bin/env python import rospy import math from tf import transformations from geometry_msgs.msg ...

  3. Ubuntu 14.04 网卡网关配置修改

    #添加网关route add default gw 192.168.5.1#强制修改网卡地址ifconfig eth0 192.168.5.40 netmask 255.255.255.0. 服务器需 ...

  4. Ubuntu14.04 系统复制迁移到新的机器上

    1.打包系统文件 制作启动盘,然后进入bios, #进入bios的boot标签选择sandisk启动 如果没有找到u盘进入save & exit标签页选择boot override中的sand ...

  5. TCP首部的TimeStamp时间戳选项 转载

    TCP应该是以太网协议族中被应用最为广泛的协议之中的一个,这里就聊一聊TCP协议中的TimeStamp选项.这个选项是由RFC 1323引入的,该C建议提交于1992年.到今天已经足足有20个年头.只 ...

  6. eclipse使用正则表达式查找替换

    1,Eclipse ctrl+f 打开查找框2,选中 Regular expressions (正则表达式) 去掉/* */(eclipse)        /\*(.|[\r\n])*?\*/去掉/ ...

  7. Ubuntu14.04(indigo)实现RGBDSLAMv2(数据集和实时Kinect)

    Ubuntu14.04(indigo)实现RGBDSLAMv2(数据集和实时Kinect v2) 一.在.bag数据集上跑RGBDSLAMv2 RGBDSLAMv2指的是Felix Endres大神在 ...

  8. python selenium 的配置安装

    selenium的使用需要以下几个配置步骤. (1) 首先安装selenium,使用python自带的pip进行安装.若pip配置到系统环境变量,可以直接在cmd命令行中使用,若没有配置到到环境变量, ...

  9. koa 项目中引入 mysql

    由于mysql模块的操作都是异步操作,每次操作的结果都是在回调函数中执行,现在有了async/await,就可以用同步的写法去操作数据库 Promise封装mysql模块 Promise封装 ./as ...

  10. 一个有趣的BUG/按钮disabled之后还能触发click事件

    一个很有意思的Bug 某天测试同学再次向我反馈,你这个删除按钮虽然置灰了,但是还是可以点击啊? 我:????(黑人问号) 卧槽?不可能啊,按钮都disabled了,怎么还可以点击?还能触发click事 ...