POJ 2594 Treasure Exploration
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?
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.
Sample Input
1 0
2 1
1 2
2 0
0 0
Sample Output
1
1
2
Source
POJ Monthly--2005.08.28,Li Haoyuan
改版的最小路径覆盖。
这道题允许一个点被多条路径覆盖。
也就是被匹配过的点还可以被匹配。
如果对于二分图匹配的过程进行处理时比较麻烦的。
我们可以求一边传递闭包,再进行匹配
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN=1001;
int vis[MAXN];
int link[MAXN];
int map[MAXN][MAXN];
int N,M;
bool dfs(int x)
{
for(int i=1;i<=N;i++)
{
if(map[x][i]&&!vis[i])
{
vis[i]=1;
if(!link[i]||dfs(link[i]))
{
link[i]=x;
return 1;
}
}
}
return 0;
}
struct S
{
int tall;
string a,b,c;
}s[MAXN];
int main()
{
#ifdef WIN32
freopen("a.in","r",stdin);
#else
#endif
while(scanf("%d%d",&N,&M)&&( N!=0||M!=0 ))
{
memset(vis,0,sizeof(vis));
memset(link,0,sizeof(link));
memset(map,0,sizeof(map));
for(int i=1;i<=M;i++)
{
int x,y;
scanf("%d%d",&x,&y);
map[x][y]=1;
}
for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
for(int k=1;k<=N;k++)
map[i][j]=map[i][j] | (map[i][k]&map[k][j]);
int ans=0;
for(int i=1;i<=N;i++)
{
memset(vis,0,sizeof(vis));
if(dfs(i))
ans++;
}
printf("%dn",N-ans );
}
return 0;
}
- 为你的网站加上SSL,可以使用HTTPS进行访问
- LeeCX - 开源后台管理系统简单介绍
- fastdfs 图片服务器 使用java端作为客户端上传图片
- Shiro系列(3) - What is shiro?
- 干货|用python抓取摩拜单车API数据并做可视化分析(源码)
- 干货|机器学习:Python实现聚类算法之K-Means
- 美团点餐—listview内部按钮点击事件
- C4C和CRM里获取当前登录用户分配的Organization Unit信息
- 使用Excel调用ABAP系统的函数
- 如何计算并测量ABAP及Java代码的环复杂度Cyclomatic complexity
- 漫谈版本控制系统
- 带你零基础入门express
- 动态控制C4C UI元素的显示和隐藏
- 深度学习(deep learning)发展史
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 【Flutter实战】动画核心(2/2)
- Flutter 1.17 新 Material motion 规范的预构建动画
- Canonical通过Flutter启用Linux桌面应用程序支持
- Flutter 快捷开发 Mac Android Studio 篇
- TRTC Android端开发接入学习之互动直播(七)
- Flutter 实现酷炫的3D效果
- 【Flutter 实战】一文学会20多个动画组件
- 【Flutter 实战】动画序列、共享动画、路由动画
- 【Flutter 实战】自定义动画-涟漪和雷达扫描
- Flutter —布局系统概述
- 【Flutter 实战】全局点击空白处隐藏键盘
- 我对Flutter的第一次失望
- 【Flutter 实战】各种各样形状的组件
- 『Flutter-绘制篇』实现炫酷的雨雪特效
- 图书管理系统(Servlet+Jsp+Java+Mysql,附下载演示地址)