Treasure Exploration
Time Limit: 6000MS   Memory Limit: 65536K
Total Submissions: 8879   Accepted: 3635

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
【题解】
二分图可重最小路径覆盖裸题
先求传递闭包,然后连边
注意时间,数组尽量开小

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5
 6 inline void read(int &x)
 7 {
 8     x = 0;char ch = getchar(), c = ch;
 9     while(ch < '0' || ch > '9')c = ch, ch = getchar();
10     while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
11     if(c == '-')x = -x;
12 }
13
14 const int INF = 0x3f3f3f3f;
15
16 struct Edge
17 {
18     int u,v,next;
19     Edge(int _u, int _v, int _next){u = _u, v = _v, next = _next;}
20     Edge(){}
21 }edge[250010];
22
23 int head[510], cnt;
24
25 inline void insert(int a, int b)
26 {
27     edge[++cnt] = Edge(a,b,head[a]);
28     head[a] = cnt;
29 }
30
31 int n,m,lk[510],b[510],g[510][610];
32
33 int dfs(int u)
34 {
35     for(register int pos = head[u];pos;pos = edge[pos].next)
36     {
37         int v = edge[pos].v;
38         if(b[v])continue;
39         b[v] = 1;
40         if(lk[v] == -1 || dfs(lk[v]))
41         {
42             lk[v] = u;
43             return 1;
44         }
45     }
46     return 0;
47 }
48
49 int xiongyali()
50 {
51     int ans = 0;
52     memset(lk, -1, sizeof(lk));
53     for(register int i = 1;i <= n;++ i)
54     {
55         memset(b, 0, sizeof(b));
56         ans += dfs(i);
57     }
58     return ans;
59 }
60
61 int main()
62 {
63     while(scanf("%d %d", &n, &m) != EOF && (n + m))
64     {
65         memset(edge, 0, sizeof(edge));
66         memset(head, 0, sizeof(head));
67         memset(g, 0, sizeof(g));
68         cnt = 0;
69         int tmp1, tmp2;
70         for(register int i = 1;i <= m;++ i)
71         {
72             read(tmp1), read(tmp2);
73             g[tmp1][tmp2] = 1;
74         }
75         for(register int k = 1;k <= n;++ k)
76             for(int i = 1;i <= n;++ i)
77                 for(int j = 1;j <= n;++j)
78                     g[i][j] |= g[i][k] && g[k][j];
79         for(register int i = 1;i <= n;++ i)
80             for(int j = 1;j <= n;++ j)
81                 if(g[i][j]) insert(i, j);
82         printf("%d\n", n - xiongyali());
83     }
84     return 0;
85 } 

POJ2594

转载于:https://www.cnblogs.com/huibixiaoxing/p/7585701.html

POJ2594 Treasure Exploration相关推荐

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

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

  2. POJ--2594|Treasure Exploration

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

  3. Treasure Exploration

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

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

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

  5. poj 2594 Treasure Exploration

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

  6. POJ Treasure Exploration 【DAG交叉最小路径覆盖】

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

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

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

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

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

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

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

最新文章

  1. json11库的使用
  2. 手把手教你ARC——iOS/Mac开发ARC入门和使用
  3. 神经网络模式识别matlab,基于matlab仿真的神经网络模式识别
  4. iw linux交叉编译,iw交叉编译
  5. 安装云端服务器操作系统,安装云端服务器操作系统
  6. 2021 ACDU China Tour-北京站暨数据库大咖讲坛(第3期)成功举办!(附PPT下载)
  7. 仪征技师学院计算机,技师学院2019年下半年江苏省大学英语、大学计算机统考工作圆满结束...
  8. lxc设置网络为公网IP
  9. 百度站内搜索应该注意哪些方面?
  10. 【Latex】Latex小论文模板
  11. 经纬度转换,度转度分秒,度分秒转为度,前端js
  12. 管道无损检测python_初用python-docx
  13. linux红帽子系统作用,linux 红帽子9.0操作系统怎么装?
  14. Cache的Insert 和Add 方法引发的血案
  15. OCT图像层次分割相关论文泛读
  16. 想自己做个网站,常用的自助建站哪个好呢?需要注意什么
  17. MFC Windows 程序设计[192]之六只眼八卦图按钮组(附源码)
  18. 别害怕,C++容器的迭代器其实好用又不难
  19. 国产麒麟系统忘记密码重置办法(5步解决)
  20. 基于单片机的数字秒表

热门文章

  1. SlidingMenu的使用,结合Fragment(eclipse环境)
  2. 常用JQuery插件整理
  3. flutter 几秒前, 几分钟前, 几小时前, 几天前...
  4. JavaScript 标准参考教程-阅读总结(三)
  5. 物联网技术周报第 143 期: Unity 3D 和 Arduino 打造虚拟现实飞行器
  6. 智慧城市的互联网大脑架构图:大社交网络与智慧城市结合是关键
  7. ElasticSearch创建、修改、获取、删除、索引Indice mapping和Index Template案例
  8. R语言编程艺术(3)R语言编程基础
  9. Java并发编程-ReentrantLock源码分析
  10. 《从零开始学Swift》学习笔记(Day 66)——Cocoa Touch设计模式及应用之通知机制...