传送门:http://poj.org/problem?id=2594

Treasure Exploration
Time Limit: 6000MS   Memory Limit: 65536K
Total Submissions: 9802   Accepted: 3979

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

POJ Monthly--2005.08.28,Li Haoyuan

题意概括:

给一个 N个节点 M 条边的有向图,机器人会沿着路径前进,问最少放多少机器人可以把所有的点走完。

解题思路:

如果只是按普通的最小路径覆盖会出现问题,两个可以通过一个结点(或多个)可以相连的结点 有可能不被匹配到,导致路径数不是最少的。原因就在于路径可以交叉。

所以先Floyd跑一遍求出原图的传递闭包,再跑最小路径覆盖就能解决上面的问题了。

AC code:

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <algorithm>
 4 #include <cstring>
 5 #include <cmath>
 6 #define INF 0x3f3f3f3f
 7 using namespace std;
 8 const int MAXN = 510;
 9 int g[MAXN][MAXN];
10 int linker[MAXN];
11 bool used[MAXN];
12 int N, M;
13
14 bool Find(int x)
15 {
16     for(int i = 1; i <= N; i++){
17         if(!used[i] && g[x][i]){
18             used[i] = true;
19             if(linker[i] == -1 || Find(linker[i])){
20                 linker[i] = x;
21                 return true;
22             }
23         }
24     }
25     return false;
26 }
27 void Floyd()
28 {
29     for(int i = 1; i <= N; i++){
30         for(int j = 1; j <= N; j++){
31             for(int k = 1; k <= N; k++){
32                 if(g[i][k] == 1 && g[k][j] == 1) g[i][j] = 1;
33             }
34         }
35     }
36 }
37
38 void init()
39 {
40     memset(g, 0,sizeof(g));
41     memset(linker, -1, sizeof(linker));
42 }
43 int main()
44 {
45     int u, v;
46     while(~scanf("%d%d", &N, &M) && (N+M)){
47         init();
48         while(M--){
49             scanf("%d%d", &u, &v);
50             g[u][v] = 1;
51         }
52         Floyd();
53         int ans = 0;
54         for(int i = 1; i <= N; i++){
55             memset(used, 0, sizeof(used));
56             if(Find(i)) ans++;
57         }
58         printf("%d\n", N-ans);
59     }
60     return 0;
61 }

View Code

POJ Treasure Exploration 【DAG交叉最小路径覆盖】相关推荐

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

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

  2. DAG的最小路径覆盖和二分图的最大匹配

    DAG的最小路径覆盖和二分图的最大匹配 DAG的最小路径覆盖是指找最小数目的互相不相交的有向路径,满足DAG的所有顶点都被覆盖. 首先给出公式:DAG的最小路径覆盖数=DAG图中的节点数-相应二分图中 ...

  3. exam1802 Bounty Hunter II(DAG的最小路径覆盖)

    原文:http://www.cnblogs.com/jackiesteed/articles/2043934.html DAG的最小路径覆盖是指找最小数目的互相不相交的有向路径,满足DAG的所有顶点都 ...

  4. 二分图大讲堂——彻底搞定最大匹配数(最小覆盖数)、最大独立数、最小路径覆盖、带权最优匹配

    二分图匹配 二分图大讲堂--彻底搞定最大匹配数(最小覆盖数).最大独立数.最小路径覆盖.带权最优匹配(转) 文本内容框架: §1图论点.边集和二分图的相关概念和性质 §2二分图最大匹配求解 匈牙利算法 ...

  5. 【POJ - 2594】Treasure Exploration(floyd传递闭包 + 最小路径覆盖,图论)

    题干: Have you ever read any book about treasure exploration? Have you ever see any film about treasur ...

  6. poj 2594 Treasure Exploration 最小路径覆盖

    题目链接:http://poj.org/problem?id=2594 建图很重要!!! 大致题意: 给出一个由n个顶点m条边组成的有向无环图.求最少可以同时存在多少路径,使得这些路径可以覆盖所有的点 ...

  7. POJ - 2594 Treasure Exploration(最小路径覆盖-二分图最大匹配+传递闭包)

    题目链接:点击查看 题目大意:给出一个有向图,现在需要让最少的机器人沿着图遍历所有点,求出最少需要机器人的数量,注意每个点可以重复遍历 题目分析:因为要遍历所有点,所以还是变成了二分图的最小路径覆盖问 ...

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

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

  9. 1350 Taxi Cab Scheme DAG最小路径覆盖

    对于什么是DAG最小路径覆盖以及解题方法在我的另外的博客已经有了.http://www.cnblogs.com/Potato-lover/p/3980470.html 此题的题意: 公交车(出租车)车 ...

最新文章

  1. python模拟高并发_Python基于gevent实现高并发代码实例
  2. go context包的WithTimeout和WithCancel的使用
  3. Zookeeper下载
  4. Unity-3d Day06
  5. IReport报表分组与分组统计
  6. dataframe输出某列的数据以及统计某列的取值种数+输出某行数据
  7. junit 测试 异常_使用JUnit规则测试预期的异常
  8. hibernate之多对多关联映射
  9. 小米台灯底座接口很松_小米黑科技,AirPods和小米10 Pro伴侣,ZMI无线充蓝牙音箱体验...
  10. Powershell 自定义对象小技巧
  11. 高仿斗鱼 android,Android 高仿斗鱼滑动验证码
  12. 下载网页视频 下载网页音乐 一般视频音频和m3u8均可
  13. 卸载python2_彻底卸载python
  14. oracle删除redo 未重启,卸载金山和瑞星后未重启就安装了卡巴,系统进不去了
  15. 究竟wifi是怎么定位我的
  16. 【微信开发第一章】SpringBoot实现微信公众号创建菜单,同步菜单功能
  17. SaltStacks三:写法和高级状态
  18. 常用激活函数--小白角度 TensorFlow 机器学习 神经网络 选取
  19. USB数据端子 type-A/B/C
  20. 按位运算符与逻辑运算符的区别

热门文章

  1. The Geodetic Set Problem UVA - 1198
  2. 华硕FL5900U如何关闭ahci_实战华硕B360主板RX580显卡安装苹果macOS 10.14 Mojave
  3. NBA表格_双红!34中24!NBA季后赛【掘金vs湖人】
  4. qt程序异常结束crashed
  5. CSMA/CD中重传与冲突检测机制
  6. oracle中的冲销日记账,OraEBSR12GL日记账业务操作09:日记账冲销处理
  7. socket通信read丢失数据可能原因
  8. Scrapy爬虫项目——阿里文学当当网
  9. new Object()和Object.create()的区别
  10. 优秀项目经理的六个习惯