题目链接: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. Oracle - 特殊字符问题

    Oracle更新表字段或者查询表字段时内容中含有特殊字符&的解决方法 现象 解决方式 1. 字符串拼接 UPDATE T_MENU_INFO SET menu_code='/ABeptjk/g ...

  2. pyecharts v1 版本 学习笔记 柱状图

    柱状图 bar 基本演示例子 from pyecharts import options as opts from pyecharts.charts import Bar c =( Bar().add ...

  3. Public model for matrix

    以下是可以加减乘除(就是乘逆矩阵啦)以及求若干次幂.行列式和逆的矩阵模板. 欢迎大家指正其中可能存在的错误(只验证了求逆的正确性). 顺便提一下这种复杂度低于定义式求逆的方法,来自于我的高等代数书,思 ...

  4. [BJOI2019]排兵布阵 DP

    [BJOI2019]排兵布阵 DP 比较好想的DP,设\(dp[i][j]\)表示第\(i\)个城堡时,已派出\(j\)个士兵.决策时,贪心派出恰好严格大于某一玩家派出的数量的两倍(不然浪费).我们发 ...

  5. OpenCV2.4.5 加 Cuda5.0在vs2010下工

    想用opencv结合gpu加速处理,想重新编译opencv结合cuda模块无奈总出错 在国外网站上搜到一个cmakelists比较靠谱,项目可以生成,但还没有测试程序把list贴出来 ######## ...

  6. Echarts——关系图(人民的名义为例,简化)源码

    参考博文:https://www.cnblogs.com/emrys5/p/echart-relationship-map.html <!DOCTYPE html> <html> ...

  7. 2019腾讯前端技术大会资源TWeb

    扫码关注公众号 回复“TWeb”即可获取“2019腾讯前端技术大会”的PPT

  8. PHP+CI框架+Memcache集成

    一.目录结构 二.具体代码 MemcacheCluster.php <?php /** * 一致性哈希memcache分布式,采用的是虚拟节点的方式解决分布均匀性问题,查找节点采用二分法快速查找 ...

  9. go之构造体方法

    package main import ( "fmt" "math" ) type Vertexs struct { X, Y float64 } //Abs ...

  10. 创建createElement

    let oDiv = { tag:'div',  props:{ id:'box' } }:   let oP = createElement('p',{'class':'list'},['周一']) ...