POJ 2594 Treasure Exploration-有向图最小路径覆盖&Floyd
来源:互联网 发布:科勒有几家网络授权店 编辑:程序博客网 时间:2024/05/28 15:11
这题大意是给你有向图,让你求出最少几个机器人可以走完所有的点,不同的机器人可以走相同的点。
如果机器人不能走相同的点,就直接求出最小路径覆盖就可以了,加上这个条件后,就要用Floyd求出所有能走的路径,再求最小路径覆盖。
最小路径覆盖 = 顶点总数 - 二分匹配数
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn = 1550;int e[maxn][maxn],match[maxn],book[maxn];int n,m;int dfs(int u){ int i; for(i=1;i<=n;i++) { if(book[i]==0 && e[u][i] == 1) { book[i] = 1; if(match[i] ==0 || dfs(match[i])) { match[i] = u; return 1; } } } return 0;}int main(void){ int i,j,k,t1,t2,sum; while(scanf("%d%d",&n,&m)==2) { if(!n && !m) break; memset(e,0,sizeof(e)); sum = 0; for(i=0;i<m;i++) { scanf("%d%d",&t1,&t2); e[t1][t2] = 1; } for(i=1;i<=n;i++)//Floyd求闭包 for(j=1;j<=n;j++) if(e[i][j] == 0) for(k=1;k<=n;k++) if(e[i][k] == 1 && e[k][j] == 1) { e[i][j] = 1; break; } memset(match,0,sizeof(match)); for(i=1;i<=n;i++) { memset(book,0,sizeof(book)); if(dfs(i)) sum++; } printf("%d\n",n-sum); }}
0 0
- POJ 2594 Treasure Exploration-有向图最小路径覆盖&Floyd
- POJ 2594 Treasure Exploration(最小路径覆盖-hungary+Floyd)
- POJ 2594 Treasure Exploration (floyd判断联通+最小路径覆盖)
- poj 2594 Treasure Exploration (最小路径覆盖+Floyd缩点)
- POJ 2594 Treasure Exploration 最小路径覆盖
- HDU 2594 Treasure Exploration(有向图最小可重叠路径覆盖)
- (floyd+最小路径覆盖) Treasure Exploration (P2594)
- POJ2594 Treasure Exploration【二分图最小路径覆盖】【Floyd】
- POJ 2594 Treasure Exploration(匈牙利算法—最小路径覆盖 + floyd)
- poj 2594 Treasure Exploration(最小路径覆盖(可重点)+floyd)
- POJ-2594 Treasure Exploration floyd传递闭包+最小路径覆盖,nice!
- POJ 2594 Treasure Exploration(最小路径覆盖+Floyd求传递闭包)
- Treasure Exploration(POJ_2594) -有向图可重复点-最小路径覆盖
- POJ 2594 Treasure Exploration(传递闭包+最小路径覆盖)
- poj 2594 Treasure Exploration最小路径覆盖+传递闭包
- POJ 2594 Treasure Exploration(最小路径覆盖变形)
- POJ 题目2594 Treasure Exploration(最小路径覆盖)
- poj 2594 Treasure Exploration 最小路径覆盖/最大匹配
- 【bzoj 3832】 [Poi2014] Rally (权值线段树+拓扑排序)
- Android 中创建Java项目的Date的转换工具
- 77.A problem is easy
- WIN7_64搭建CUDA开发环境
- POJ-2828 Buy Tickets【线段树 单点更新】
- POJ 2594 Treasure Exploration-有向图最小路径覆盖&Floyd
- 78.a letter and a number
- mac下自带的php无法加载验证码的问题
- 【ITOO技术篇】——MVC框架和EF映射
- 关系数据库查询优化的初次体验
- HDU 4514(并查集加树的直径)
- Cow Marathon
- 剑指offer 中问题的眼前一亮的解法
- 判断一个数是否是素数。