POJ2594 Treasure Exploration
Time Limit: 6000MS | Memory Limit: 65536K | |
Total Submissions: 8193 | Accepted: 3358 |
Description
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
Output
Sample Input
1 0
2 1
1 2
2 0
0 0
Sample Output
1
1
2
Source
特殊的最小路径覆盖,每个点可以被不同的路径重复经过。
用floyd判断两个点是否间接联通(传说这叫传递闭包),然后匈牙利算法找路径覆盖即可。
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int mp[mxn][mxn];
int link[mxn];
bool vis[mxn];
int n,m;
bool DFS(int u){
int i,j;
for(i=;i<=n;i++){
if(mp[u][i] && !vis[i]){
vis[i]=;
if(link[i]==- || DFS(link[i])){
link[i]=u;
return ;
}
}
}
return ;
}
int solve(){
int res=;
for(int i=;i<=n;i++){
memset(vis,,sizeof vis);
if(DFS(i))res++;
}
return res;
}
int main(){
int i,j,u,v;
while(scanf("%d%d",&n,&m)){
if(!n && !m)break;
memset(mp,,sizeof mp);
memset(link,-,sizeof link);
for(i=;i<=m;i++){
u=read();v=read();
mp[u][v]=;
}
for(int k=;k<=n;k++)
for(i=;i<=n;i++)
for(j=;j<=n;j++){
mp[i][j]|=mp[i][k]&mp[k][j];
}
int res=solve();
printf("%d\n",n-res);
}
return ;
}
POJ2594 Treasure Exploration的更多相关文章
- POJ2594 Treasure Exploration(最小路径覆盖)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8550 Accepted: 3 ...
- POJ2594 Treasure Exploration[DAG的最小可相交路径覆盖]
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8301 Accepted: 3 ...
- POJ-2594 Treasure Exploration,floyd+最小路径覆盖!
Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...
- POJ-2594 Treasure Exploration floyd传递闭包+最小路径覆盖,nice!
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8130 Accepted: 3 ...
- POJ2594 Treasure Exploration【DAG有向图可相交的最小路径覆盖】
题目链接:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K T ...
- [POJ2594] Treasure Exploration(最小路径覆盖-传递闭包 + 匈牙利算法)
传送门 引子: 有一个问题,是对于一个图上的所有点,用不相交的路径把他们覆盖,使得每个点有且仅属于一条路径,且这个路径数量尽量小. 对于这个问题可以把直接有边相连的两点 x —> y,建一个二分 ...
- POJ2594 Treasure Exploratio —— 最小路径覆盖 + 传递闭包
题目链接:https://vjudge.net/problem/POJ-2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 655 ...
- POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 9794 Accepted: 3 ...
- poj 2594 Treasure Exploration (二分匹配)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6558 Accepted: 2 ...
随机推荐
- Jira-Clone与发邮件的使用
1.克隆问题 包括两部分,先进行Clone,再进行移动 a.选择要克隆的问题,点击More Actions-Clone,在弹出框“复制问题”中,点击“创建”按钮即克隆成功 b.移动问题,点击More ...
- JAVA NIO概述(一):I/O模型
NIO是jdk1.4加入的新功能,我们一般成为非阻塞IO,在1.4之前,JAVA中的都是BIO(堵塞IO),BIO有以下几个缺点: 没有数据缓冲区,I/O性能存在问题 没有C/C++中channel( ...
- 查询OOP课程
--检测有没有名称为MySchool的数据库 use master if exists (select * from sysdatabases where name='myschool') begin ...
- 用yo命令创建项目
1,npm install -g yo 安装yeoman 2,npm install -g generator-webapp 安装项目脚手架(生成器) 如果安装angular的项目后面则是genera ...
- 手机中点击链接或button按钮出现黄色边框的解决办法
a,input,button{outline: none; -webkit-tap-highlight-color: rgba(255, 255, 255, 0); -webkit-focus-rin ...
- 项目管理和缺陷跟踪工具Redmine
官网: http://www.redmine.org/ http://demo.redmine.org/ 下载: http://www.redmine.org/projects/redmine/wik ...
- 使用C#改变鼠标的指针形状
1.在一个无标题的窗体中用MOUSEMOVE事件判断鼠标坐标是否到达窗体的边缘,如果是的话将鼠标指针改为可调整窗体大小的双向箭头. private void Form1_MouseMove(o ...
- C#委托Action、Action<T>、Func<T>、Predicate<T>
CLR环境中给我们内置了几个常用委托Action. Action<T>.Func<T>.Predicate<T>,一般我们要用到委托的时候,尽量不要自己再定义一 个 ...
- JS 之DOM range对象
DOM范围 DOM中的range对象是DOM2中新定义的接口.通过这个对象可以选择文档中的某个区域,而不必考虑节点的界限. 创建范围 document.createRange()创建一个范围,这个范围 ...
- vi 命令 用法
一.Unix编辑器概述 编辑器是使用计算机的重要工具之一,在各种操作系统中,编辑器都是必不可少的部件.Unix及其相似的ix 操作系统系列中,为方便各种用户在各个不同的环境中使用,提供了一系列的ex编 ...