Treasure Exploration(二分最大匹配+floyd)
| Time Limit: 6000MS | Memory Limit: 65536K | |
| Total Submissions: 7455 | Accepted: 3053 |
Description
Input
Output
Sample Input
1 0
2 1
1 2
2 0
0 0
Sample Output
1
1
题解:需要加上floyd,用上vector 竟然re了;
ac代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN=;
int mp[MAXN][MAXN],vis[MAXN],usd[MAXN];
int N;
bool dfs(int u){
for(int i=;i<=N;i++){
if(!vis[i]&&mp[u][i]){
vis[i]=;
if(!usd[i]||dfs(usd[i])){
usd[i]=u;return true;
}
}
}
return false;
}
void floyd(){
for(int i=;i<=N;i++)
for(int j=;j<=N;j++)
if(mp[i][j]==){
for(int k=;k<=N;k++)
if(mp[i][k]&&mp[k][j])
mp[i][j]=;
}
}
int main(){
int M;
while(scanf("%d%d",&N,&M),N|M){
int a,b;
mem(mp,);mem(usd,);
while(M--){
scanf("%d%d",&a,&b);
mp[a][b]=;
}
int ans=;
floyd();
for(int i=;i<=N;i++){
mem(vis,);
if(dfs(i))ans++;
}
printf("%d\n",N-ans);
}
return ;
}
re代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN=;
int vis[MAXN],usd[MAXN];
vector<int>vec[MAXN];
int N;
bool dfs(int u){
for(int i=;i<vec[u].size();i++){
int v=vec[u][i];
if(!vis[v]){
vis[v]=;
if(!usd[v]||dfs(usd[v])){
usd[v]=u;return true;
}
}
}
return false;
}
void floyd(){
for(int i=;i<=N;i++){
for(int k=;k<vec[i].size();k++)
for(int j=;j<vec[vec[i][k]].size();j++){
vec[i].push_back(vec[vec[i][k]][j]);
}
}
}
int main(){
int M;
while(scanf("%d%d",&N,&M),N|M){
int a,b;
mem(usd,);
for(int i=;i<=N;i++)vec[i].clear();
while(M--){
scanf("%d%d",&a,&b);
vec[a].push_back(b);
}
floyd();
int ans=;
for(int i=;i<=N;i++){
mem(vis,);
if(dfs(i))ans++;
}
printf("%d\n",N-ans);
}
return ;
}
Treasure Exploration(二分最大匹配+floyd)的更多相关文章
- poj 2594 Treasure Exploration (二分匹配)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6558 Accepted: 2 ...
- POJ-2594 Treasure Exploration,floyd+最小路径覆盖!
Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...
- POJ 2594 —— Treasure Exploration——————【最小路径覆盖、可重点、floyd传递闭包】
Treasure Exploration Time Limit:6000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64 ...
- POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 9794 Accepted: 3 ...
- POJ-2594 Treasure Exploration floyd传递闭包+最小路径覆盖,nice!
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8130 Accepted: 3 ...
- POJ2594 Treasure Exploration(最小路径覆盖)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8550 Accepted: 3 ...
- Poj 2594 Treasure Exploration (最小边覆盖+传递闭包)
题目链接: Poj 2594 Treasure Exploration 题目描述: 在外星上有n个点需要机器人去探险,有m条单向路径.问至少需要几个机器人才能遍历完所有的点,一个点可以被多个机器人经过 ...
- Treasure Exploration POJ - 2594 【有向图路径可相交的最小路径覆盖】模板题
Have you ever read any book about treasure exploration? Have you ever see any film about treasure ex ...
- POJ2594 Treasure Exploration【DAG有向图可相交的最小路径覆盖】
题目链接:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K T ...
随机推荐
- SQL Server索引进阶:第五级,包含列
原文地址: Stairway to SQL Server Indexes: Level 5, Included Columns 本文是SQL Server索引进阶系列(Stairway to SQL ...
- w3c教程
http://www.w3cfuns.com/course.php http://www.w3cfuns.com/home.php?mod=space&uid=5434413&do=b ...
- JavaScript使用button提交表单
<form action="test.html" method="POST"> <input type="button" ...
- Spring学习之注入方式
我们知道,Spring对象属性的注入方式有两种:设值注入和构造注入. 假设有个类为People,该对象包含三个属性,name和school还有age,这些属性都有各自的setter和getter方法, ...
- mysql修改用户名和密码
修改用户名 mysql> use mysql; 选择数据库Database changedmysql> update user set user="dns" wher ...
- X509Certificate2 本地正常,放到线上内部错误
iis 找到部署的站点应用连接池,右键高级设置,找到“加载用户配置文件”改为true.window service2008 默认为false的.
- Java中单态设计模式
Java中单态设计模式 2011-09-23 16:38:46| 分类: Java | 标签:technology! |举报|字号 订阅 此博文是转自新浪博客中一名叫做"俊俊的 ...
- 一次搞懂 Assets Pipeline 转载自http://gogojimmy.net/2012/07/03/understand-assets-pipline/
Assets Pipeline 是 Rails 3.1 一個重要的功能,一直並沒有很去了解其特性,但因為最近都在寫前端的東西在 assets pipeline 的東西上跌跌撞撞了不少次(尤其在 dep ...
- 打印 PHP $_SERVER 常量
foreach( $_SERVER as $var => $value){ echo $var.' '.$value.'<br>'; };
- CentOS5.4下安装codeblocks 12.11
centos6.3下安装codeblock简单多了,这些开源的软件也都在不断进步.原来装过codeblocks10.05,忘了,这次安装又花了我半天时间,最后总算搞定. 先是安装了wxGTK-2.8. ...