soj2093: Farmer John
来源:互联网 发布:樱井知香迅雷种子磁力 编辑:程序博客网 时间:2024/05/19 17:22
soj上的一题,自己没想清楚就做结果坑了好久,先上题目
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
0 0
- soj2093: Farmer John
- Farmer John的故事
- 广搜基础 Farmer John
- Farmer John has built a sand castle
- Sicily 13859. Farmer John has no Large Brown Cow
- hrbust 1450 Farmer John【计算集合+最短路SPFA】
- bzoj 3368: [Usaco2004]Farmer John's View 约翰看山
- 安慰奶牛 问题描述 Farmer John变得非常懒,他不想再继续维
- John
- John
- John
- John
- 农民企业家 Farmer-turned-entrepreneur
- HDU 4380 - Farmer Greedy
- TOJ 3853 Farmer Flabby
- 18001 Farmer Cat
- Farmer Bill's Problem
- HDU 4380 Farmer Greedy
- 存储过程 创建全局临时表
- meta中的viewport指令
- 网络协议消息分片
- vs2005编译pjsip
- (Memory and Resource) Leak detection for WinCE
- soj2093: Farmer John
- GUI 创建个Frame,往里面插入Panel,Panel的大小随Frame大小调整 setLayout setBounds
- Linux下.sh文件语法
- 各种远程通信协议分析、比较
- 图文记录apache静态资源服务器安装
- ViewConfiguration类的使用
- uva---489
- Shell脚本调试技术
- 扬州旅游app(一)