poj 2595 Treasure Exploration
来源:互联网 发布:侧卧按键开关封装淘宝 编辑:程序博客网 时间:2024/05/21 10:32
题目链接:http://poj.org/problem?id=2594
思路:最小覆盖路径的变形,因为点可以重复经过,用floyd求传递闭包
#include<cstdio>#include<cstring>using namespace std;const int num=505;int n,m,map[num][num],vis[num],match[num];void floyd(){ int i,j,k; for(i=1;i<=n;i++) for(j=1;j<=n;j++) for(k=1;k<=n;k++) if(map[j][i]&&map[i][k]) map[j][k]=1;}int deal(int a){ int i; for(i=1;i<=n;i++) { if(vis[i]==0&&map[a][i]) { vis[i]=1; if(match[i]==-1||deal(match[i])) { match[i]=a; return 1; } } } return 0;}int main(){ int i,j,ans,a,b; //freopen("in.txt","r",stdin); while(scanf("%d%d",&n,&m)!=EOF) { if(n==0&&m==0) break; memset(match,-1,sizeof(match)); memset(map,0,sizeof(map)); for(i=0;i<m;i++) { scanf("%d%d",&a,&b); map[a][b]=1; } floyd(); ans=0; for(i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); ans+=deal(i); } printf("%d\n",n-ans); } return 0;}
0 0
- poj 2595 Treasure Exploration
- poj 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- POJ 2594 Treasure Exploration
- poj 2594 Treasure Exploration
- POJ--2594|Treasure Exploration
- Treasure Exploration POJ
- POJ 2594 Treasure Exploration 最小路径覆盖
- poj 2594 Treasure Exploration 二分图匹配
- 正确理解ThreadLocal
- leetcode 刷题之路 54 Jump Game
- Codeforces Round #260 (Div. 2)A. Laptops
- sap les
- 后缀数组
- poj 2595 Treasure Exploration
- Codeforces Round #260 (Div. 2) B. Fedya and Maths
- 区别之守护进程 孤儿进程 僵尸进程
- jmeter使用2-springmvc request
- 25465413214654
- Backbone.js源码分析系列之Collection模块
- 黑马程序员--高新技术(内省)
- 是发个V大分还不
- Java中的Class类以及获取Class对象的三种方式