poj2594 treasure exploration
来源:互联网 发布:自动签到脚本 python 编辑:程序博客网 时间:2024/05/16 11:53
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?
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.
最小路径覆盖。
注意与模板不同的是路径可重叠。
所以用floyd判断任意两点是否连通,在联通的点之间连边,再求最小路径覆盖。
#include<cstdio>#include<cstring>#define M(a) memset(a,0,sizeof(a))int map[2000][2000],v[2000],f[2000],first[2000],next[2000000],to[2000000];int m,n;bool dfs(int p){int i,j,k,x,y,z;for (i=first[p];i;i=next[i]) if (!v[to[i]]) { v[to[i]]=1; if (!f[to[i]]||dfs(f[to[i]])) { f[to[i]]=p; return 1; } }return 0;}int main(){int i,j,k,x,y,z,ans,cnt;while (scanf("%d%d",&n,&m)&&n){M(map);M(f);M(first);M(next);M(to);for (i=1;i<=m;i++){scanf("%d%d",&x,&y);map[x][y]=1;}for (k=1;k<=n;k++) for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (i!=j) map[i][j]=map[i][j]||(map[i][k]&&map[k][j]);cnt=0;for (i=1;i<=n;i++) for (j=1;j<=n;j++) if (map[i][j]) { cnt++; next[cnt]=first[2*i]; first[2*i]=cnt; to[cnt]=2*j+1;}ans=n;for (i=2;i<=2*n;i+=2){M(v);if (dfs(i)) ans--;}printf("%d\n",ans);}}
0 0
- poj2594 Treasure Exploration
- POJ2594-Treasure Exploration
- poj2594:Treasure Exploration
- poj2594 treasure exploration
- POJ2594-Treasure Exploration
- 【POJ2594】Treasure Exploration 宝藏勘探
- POJ2594-Treasure Exploration(最小路径覆盖变形)
- poj2594 Treasure Exploration(二分图)
- POJ2594 Treasure Exploration(最小路径覆盖)
- poj2594 Treasure Exploration【最小路径覆盖】
- POJ2594 Treasure Exploration 最小点覆盖题目[有重复点]
- POJ2594 Treasure Exploration【二分图最小路径覆盖】【Floyd】
- 可重叠的最小路径覆盖 poj2594 Treasure Exploration
- 【POJ2594】Treasure Exploration 宝藏勘探 二分图最大匹配
- poj2594 Treasure Exploration(可相交最小路径覆盖)
- poj2594 Treasure Exploration 最小路径覆盖=顶点数-最大匹配数
- poj2594——Treasure Exploration(闭包+最小路径覆盖)
- poj2594-Treasure Exploration(最小路径覆盖,最大匹配,floyed(优化))
- Android的udp回显测试源码
- jdk linux 解压安装
- 浙大 PAT Advanced level 1018. Public Bike Management (30)
- 如何查找在python中的模块和方法
- 1004. 成绩排名 (20)
- poj2594 treasure exploration
- python中with语句的用法
- JAVA基础之表达式,语句,和块
- ViewPager+Fragment实现页卡切换
- 蓝桥杯 海盗分金币
- 反射--获取成员函数
- angularJS总结
- 图片压缩保存 处理三星拍照图片旋转问题的部分方法
- HDU 2102 A计划