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,一经查实,立即删除!

相关文章

samba and AD

背景:在上次的背景之下(见上一文章),管理员发现公司内现有部门不多,但员工数量非常的多.如果按照用户一个一个的去创建用户并用smbpasswd增加samba的登陆用户非常的麻烦.而且公司内已经存在一台windows 2003 server域控制器(建立方法),并且包含所有员工的帐号信息.在此管理员想…

jquery 简单分页插件jQuerypage

昨天项目手机端要用到table的分页&#xff0c;考虑到手机端界面小&#xff0c;系统数据不多&#xff0c;在没考虑大批量数据处理的前提前就下载了这个插件&#xff0c;简单。 展示数据datas为json格式。 <!DOCTYPE html> <html lang"ch"> <head>&l…

Google Closure Complier的使用

参考老赵的这篇 俺觉得GC最精华的还是它的高级压缩功能&#xff0c;只不过用起来用点麻烦: 最好的是不需要引用第三方类库, 如果需要用得加上编译参数也不需要提供给第三方不要将js写到html中html里面不要有静态函数调用, 比如οnclickXXX不使用[XXX]的形式访问属性,或者说使用…

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

如何删除隐藏着的网卡

如果你将一个虚拟机&#xff08;机器名VM1&#xff09;的vhd文件直接新建成另一个虚拟机&#xff08;机器名VM2&#xff09;&#xff0c;此时VM1虚机已经删除。但是你还是无法将VM2虚机的IP地址设置成和VM1虚机一样的IP地址&#xff0c;原因是IP地址冲突&#xff0c;而VM2虚机中…

牛顿插值法及其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…

【原创中】儿子,听爸爸跟你说

可爱的宝贝儿子&#xff1a;可能你现在正在家里小床上酣睡&#xff0c;可惜爸爸不能在你身边陪着你。无数个夜晚&#xff0c;你妈妈他们睡在你身边照顾你&#xff0c;你知道他们有多辛苦吗&#xff1f;等你长大了&#xff0c;我会告诉你做父母的艰辛&#xff0c;我们并不是要求…

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…

GdiPlus[38]: IGPGraphicsPath (五) 路径标记

IGPGraphicsPath.SetMarker //建立一个标记 IGPGraphicsPath.ClearMarkers //取消全部标记在路径中每建立一个图形都可以同时做个 Marker,真正使用这些个标记时, 主要通过 IGPGraphicsPathIterator 的 NextMarker() 方法.下面是建立并遍历 Marker 的演示代码, 暂未使用 IGPG…

结队编程项目进度

四则运算答题计算器&#xff1a;现在已经进行到随机生成一个100以内的数字和一个10以内的数字&#xff0c;并进行减法运算转载于:https://www.cnblogs.com/juyan/p/7598434.html

微软发布3款SQL Injection攻击检测工具

随着 SQL INJECTION 攻击的明显增多&#xff0c;微软近日发布了三个免费工具&#xff0c;帮助网站管理员和检测存在的风险并对可能的攻击进行拦截。Scrawlr 下载地址&#xff1a;https://download.spidynamics.com/Products/scrawlr/这个微软和 HP合作开发的工具&#xff0c;会…

安装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…