soj2093: Farmer John
soj上的一题,自己没想清楚就做结果坑了好久,先上题目
Problem D: Farmer John
If you once took part in USACO, which is short for USA Computing Olympiad,
you will know who is Farmer John. Well, I am also sure that some of you know
nothing about him. However, it does not matter. You could just help him solve
programming tasks.
John has built a huge theme park for crops. Wow, he really looks like \A
Tall-Rich-Handsome", and the park looks like \A Gao-Da-Shang". However,
he has to face a thorny problem recently. He needs to build many irrigation
equipments for the crops in the theme park. He should guarantee that each
crop-site (denoted by a number) has an access to water source. More clearly,
he could build a water equipment in a crop-site so that the crop-site can obtain
water directly. And, any other crop-site that connects a crop-site containing a
water equipment can also obtain the water indirectly via a water pipeline.
Figure 2: An example of crop-site map.
For example, Fig. 2 shows an example of crop-site map. As shown in Fig.
2, it contains 4 crop-sites, denoted by decimal number 1, 2, 3, and 4. An edge
between two crop-sites indicates that a water pipeline can be built between
them, otherwise, it is not able to build a water pipeline. For any two crop-sites
that can be connected by a pipeline, it needs a certain cost to build the pipeline.
For instance, if we want to build a pipeline between 1 and 2 (crop-site), we need
a cost of 10, which is marked in Fig. 2. For any crop-site, if we want to build
a water equipment (water source), we also need a certain cost. For instance, if
we want to build a water equipment in 1 (crop-site), we need a cost of 100; if
we want to build a water equipment in 4, we need a cost of 5, etc.
Farmer John hopes you help him to nd the minimum cost to build all pos-
sible water equipments and pipelines so that each of the crop-sites can directly
or indirectly obtain the water. E.g. for Fig. 2, we can build all the pipelines
with a cost of 30 and build a water equipment in 2 with a cost of 50, this way,
we need a total cost of 80. However, it is not a minimum cost! We can still
build all the pipelines with a cost of 30, but build a water equipment in 4 with
a cost of 5, this way, we only need a total cost of 35 and all the crop-sites can
obtain water directly or indirectly.
6
Input
Input contains multiple cases. Each case starts with two integer n and m (0
n;m 105, m n(n
soj2093: Farmer John相关推荐
- Farmer John 木瓜地 C++
Bessie不小心游荡出Farmer John的田地,而走进了相邻的农民的地.她举起一个木瓜,木瓜对奶牛来说可是不可多得得美味.这个木瓜林像一般的威斯康星州的田地一样被分割成一个 R行C列的网格(1 ...
- Farmer John的故事
从前有个农民,名字叫约翰,于是大家叫他Farmer John(FJ).FJ养了很多奶牛,这些奶牛很聪明,它们很喜欢看自然科学和数学书,但是它们对书的ISBN码感到奇怪,于是就有了ISBN问题.渐渐的, ...
- Farmer John的故事——写给程序员们
Farmer John的故事: 从前有个农民,名字叫约翰,于是大家叫他Farmer John(FJ).FJ养了很多奶牛,这些奶牛很聪明,它们很喜欢看自然科学和数学书,但是它们对书的ISBN码感到奇怪, ...
- Farmer John's math(c++)
在CUGB队员驱车南下比赛的途中,突然发现没口粮了--饿得头晕眼花. 恰好迎面走来个人,原来是Farmer John,众所周知,FJ(Farmer John)喜欢数学,可是大家有所不知,他除了养牛,还 ...
- 2190: 【USACO】Farmer John has no Large Brown Cow
2190: [USACO]Farmer John has no Large Brown Cow 时间限制: 1.000 Sec 内存限制: 64 MB 提交: 16 解决: 12 [命题人:][下 ...
- 安慰奶牛 问题描述 Farmer John变得非常懒,他不想再继续维
package ALGO;/*安慰奶牛 时间限制:1.0s 内存限制:256.0MB问题描述Farmer John变得非常懒,他不想再继续维护供奶牛之间供通行的道路.道路被用来连接N个牧场,牧场被连续 ...
- 迷路的奶牛 Farmer John C++
描述 Farmer John的N头奶牛,总是会迷路走到农场上遥远的地方去!他需要你帮助将她们一起赶回来. 农场的草地大体是一块狭长的区域--我们可以将其想象成一条数轴,奶牛可以占据数轴上的任意整数位置 ...
- United Cows of Farmer John G
题目链接:United Cows of Farmer John G 我们考虑枚举每个右端点. 然后前面合法的左端点是哪些呢?假设当前位置为 R,上一次出现位置为L,如果未出现当成0 那么我们对于一些出 ...
- 2021.8.14【提高B组模拟6】T3 + P7527 [USACO21OPEN] United Cows of Farmer John (树状数组)
United Cows of Farmer John 题目传送门 解题思路 树状数组乱糊 AC代码 #include<cstdio> #include<cstring> usi ...
最新文章
- Operations Manager 2007 R2系列之单台性能视图
- DevExpress ChartControl大数据加载时有哪些性能优化方法
- @import和@class的区别
- FOR ALL ENTRIES IN内表排序、排重对性能的影响
- Istio调用链埋点原理剖析—是否真的“零修改”分享实录
- @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) 注解的作用
- CSDN Cookbook by Eric
- 欧几里得算法扩展欧几里得算法(基础)
- live2d sdk java_在iOS新项目中集成Live2D SDK
- UML基础(八)--构件图
- java gbk编码_java中如何得到输入的汉字的GBK编码
- 微信公众号、订阅号、服务号区别
- Linux扩展ip上限,Linux之iptables添加扩展模块实现封P2P、封国家IP
- 重学前端学习笔记(十二)--浏览器工作解析(二)
- excel网页服务器端,Excel服务VI――用Excel Web Services创建应用程
- 通信工程专业就业之------通信协议栈开发(LTE/NR)
- 敏捷Scrum指南三:Scrum角色之SM(ScrumMaster)
- Ruby+Watir搭建自动化测试框架
- 28、食物热量、卡路里查询API接口,免费好用
- Windows运行(快捷键Win+R)命令大全 及 快捷键