POJ2594 Treasure Exploration

Treasure Exploration
Time Limit: 6000MS Memory Limit: 65536K
Total Submissions: 8879 Accepted: 3635

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
【题解】
二分图可重最小路径覆盖裸题
先求传递闭包,然后连边
注意时间,数组尽量开小
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 
 6 inline void read(int &x)
 7 {
 8     x = 0;char ch = getchar(), c = ch;
 9     while(ch < '0' || ch > '9')c = ch, ch = getchar();
10     while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar();
11     if(c == '-')x = -x;
12 }
13 
14 const int INF = 0x3f3f3f3f;
15 
16 struct Edge
17 {
18     int u,v,next;
19     Edge(int _u, int _v, int _next){u = _u, v = _v, next = _next;}
20     Edge(){}
21 }edge[250010];
22 
23 int head[510], cnt;
24 
25 inline void insert(int a, int b)
26 {
27     edge[++cnt] = Edge(a,b,head[a]);
28     head[a] = cnt;
29 }
30 
31 int n,m,lk[510],b[510],g[510][610];
32 
33 int dfs(int u)
34 {
35     for(register int pos = head[u];pos;pos = edge[pos].next)
36     {
37         int v = edge[pos].v;
38         if(b[v])continue;
39         b[v] = 1;
40         if(lk[v] == -1 || dfs(lk[v]))
41         {
42             lk[v] = u;
43             return 1;
44         }
45     }
46     return 0;
47 }
48 
49 int xiongyali()
50 {
51     int ans = 0;
52     memset(lk, -1, sizeof(lk));
53     for(register int i = 1;i <= n;++ i)
54     {
55         memset(b, 0, sizeof(b));
56         ans += dfs(i);
57     }
58     return ans;
59 }
60 
61 int main()
62 {
63     while(scanf("%d %d", &n, &m) != EOF && (n + m))
64     {
65         memset(edge, 0, sizeof(edge));
66         memset(head, 0, sizeof(head));
67         memset(g, 0, sizeof(g));
68         cnt = 0;
69         int tmp1, tmp2;
70         for(register int i = 1;i <= m;++ i)
71         {
72             read(tmp1), read(tmp2);
73             g[tmp1][tmp2] = 1;
74         }
75         for(register int k = 1;k <= n;++ k)
76             for(int i = 1;i <= n;++ i)
77                 for(int j = 1;j <= n;++j)
78                     g[i][j] |= g[i][k] && g[k][j];
79         for(register int i = 1;i <= n;++ i)
80             for(int j = 1;j <= n;++ j)
81                 if(g[i][j]) insert(i, j);
82         printf("%d\n", n - xiongyali());
83     }
84     return 0;
85 } 
POJ2594

 

转载于:https://www.cnblogs.com/huibixiaoxing/p/7585701.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/268366.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mac下载maven详细步骤

1.进入官网 Maven – Welcome to Apache Maven 2.点击download 3.点击下方的apache-maven-3.8.6-bin.zip 4.下载到本地后&#xff0c;打开settings.xml文件 5.修改 settings.xml文件内容 加上 <localRepository>/Users/wangzeyu/.m2/repository1</localRepository&…

Quick Cocos2dx 场景转换问题

项目结构是这样子的&#xff1a; 主场景代码是这样子的&#xff1a; local MainScene class("MainScene", function()return display.newScene("MainScene") end)function MainScene:ctor()self.layer display.newLayer();self:addChild(self.layer)self…

阿里云云效Maven地址

https://developer.aliyun.com/mvn/guide

牛顿插值法及其C++实现

牛顿插值法 一、背景引入 相信朋友们&#xff0c;开了拉格朗日插值法后会被数学家的思维所折服&#xff0c;但是我想说有了拉格朗日插值法还不够&#xff0c;因为我们每次增加一个点都得重算所有插值基底函数&#xff0c;这样会增加计算量&#xff0c;下面我们引入牛顿插值法&a…

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on

报错如下 Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project hhh: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without sa…

ASP.NET Core 认证与授权[1]:初识认证

在ASP.NET 4.X 中&#xff0c;我们最常用的是Forms认证&#xff0c;它既可以用于局域网环境&#xff0c;也可用于互联网环境&#xff0c;有着非常广泛的使用。但是它很难进行扩展&#xff0c;更无法与第三方认证集成&#xff0c;因此&#xff0c;在 ASP.NET Core 中对认证与授权…

IDEA创建Maven项目报错- Error injecting constructor, java.lang.NoSuchMethodError: org.apache.maven.model】

1&#xff1a;报错 今天下了最新版本的maven&#xff0c;在idea中配置好maven好&#xff0c;拉取依赖报错了 2:查看报错日志 报错如下 1) Error injecting constructor, java.lang.NoSuchMethodError: org.apache.maven.model.validation.DefaultModelValidator: method <…

C# 动态加载 动态卸载

代码usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Threading;usingSystem.Reflection;namespaceUnloadDll{ classProgram { staticvoidMain(string[] args) { stringcallingDomainName AppDomain.CurrentDomain.…

python进行数据分析

1. python进行数据分析----线性回归 2. python进行数据分析------相关分析 3. python进行数据分析---python3卡方 4. 多重响应分析&#xff0c;多选题二分法思路 5. 交叉表思路&#xff0c;未发布 6. 比较均值分析思路 7. 排序题如何进行数据分析 8.python 二元Logistics Regr…

安装C语言版本tensorflow

安装 本文中的示例&#xff0c;可以点击这里下载。 参考&#xff1a;https://www.tensorflow.org/install/install_c 官网提供的方法是用一个脚本去安装&#xff1a; TF_TYPE"cpu" # Change to "gpu" for GPU support OS"linux" # Change to &qu…

Idea Error:(6, 32) java: 程序包xxx.xxx包不存解决方(亲测有效)

main方法运行不起来,报错&#xff1a;xxx.xxx包不存在&#xff0c;xxx.xxx找不到&#xff0c;实则相关的包都是存在的&#xff0c;并且可以打包成功。也就是说&#xff0c;可以打包成功但是idea不能运行 报错如下 方法一&#xff1a; 勾选了"delegate IDE build/run act…

Mac启动elasticsearch并用代码创建索引

一&#xff1a;启动ElasticSearch ES后台启动 bi目录下执行如下命令 ./elasticsearch -d 二&#xff1a;验证启动是否成功 浏览器输入&#xff0c;返回如下表示启动成功 三&#xff1a;添加es依赖 <dependency><groupId>org.elasticsearch</groupId><…

什么是 I2C

什么是 I2C I2C(Inter&#xff0d;Integrated Circuit)总线是一种由PHILIPS公司开发的两线式串行总线&#xff0c;用于连接微控制器及其外围设备。I2C总线产生于在80年代&#xff0c;最初为音频和视频设备开发&#xff0c;如今主要在服务器管理中使用&#xff0c;其中包括单个组…

阅读笔记一之《软件需求与分析》

关于我们怎样做需求分析&#xff1a; 本学期《软件需求与分析》需要掌握需求调研、需求分析和需求确认三大基本内容。以下为针对每一个内容的自己的理解。 一、需求调研 初识&#xff1a;刚开始与客户接触的时候&#xff0c;一定要建立良好的职业微信。在对需求进行分析时&…

java代码删除ElasticSearch索引

用java代码删除ElasticSearch索引 public class ElasticsearchDeleteIndexTest {public static void main(String[] args) throws IOException {RestHighLevelClient restHighLevelClient new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9…

java代码查询elasticsearch索引

用java代码查询ES索引 public class ElasticsearchSearchTest {public static void main(String[] args) throws IOException {RestHighLevelClient restHighLevelClient new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http&…

67 个JavaScript和CSS实用工具、库与资源

在这篇文章中&#xff0c;我不会与大家谈论大型的前端框架&#xff0c;如 React、Angular、Vue 等&#xff0c;也没有涉及那些流行的代码编辑器&#xff0c;如 Atom、VS Code、Sublime&#xff0c;我只想与大家分享一个有助于提升开发人员效率的工具列表合集。 或许&#xff0c…

NGINX生命周期-转

转载于:https://www.cnblogs.com/justart/p/7611427.html