HDU 1301 Jungle Roads——————最小生成树

『杭电1301』Jungle Roads Problem Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too 阅读详情

Jungle Roads

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10014    Accepted Submission(s): 7340


Problem Description

这里写图片描述>

The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to maintain. The Council of Elders must choose to stop maintaining some roads. The map above on the left shows all the roads in use now and the cost in aacms per month to maintain them. Of course there needs to be some way to get between all the villages on maintained roads, even if the route is not as short as before. The Chief Elder would like to tell the Council of Elders what would be the smallest amount they could spend in aacms per month to maintain roads that would connect all the villages. The villages are labeled A through I in the maps above. The map on the right shows the roads that could be maintained most cheaply, for 216 aacms per month. Your task is to write a program that will solve such problems.

The input consists of one to 100 data sets, followed by a final line containing only 0. Each data set starts with a line containing only a number n, which is the number of villages, 1 < n < 27, and the villages are labeled with the first n letters of the alphabet, capitalized. Each data set is completed with n-1 lines that start with village labels in alphabetical order. There is no line for the last village. Each line for a village starts with the village label followed by a number, k, of roads from this village to villages with labels later in the alphabet. If k is greater than 0, the line continues with data for each of the k roads. The data for each road is the village label for the other end of the road followed by the monthly maintenance cost in aacms for the road. Maintenance costs will be positive integers less than 100. All data fields in the row are separated by single blanks. The road network will always allow travel between all the villages. The network will never have more than 75 roads. No village will have more than 15 roads going to other villages (before or after in the alphabet). In the sample input below, the first data set goes with the map above.

The output is one integer per line for each data set: the minimum cost in aacms per month to maintain a road system that connect all the villages. Caution: A brute force solution that examines every possible set of roads will not finish within the one minute time limit.
 

Sample Input
  
9
A 2 B 12 I 25
B 3 C 10 H 40 I 8
C 2 D 18 G 55
D 1 E 44
E 2 F 60 G 38
F 0
G 1 H 35
H 1 I 35
3
A 2 B 10 C 40
B 1 C 20
0
 

Sample Output
  
216
30
 

Source
 

Recommend
Eddy  &nbsp|  &nbspWe have carefully selected several similar problems for you:   1162  1102  1217  1142  1879 
 

Statistic |  Submit |  Discuss | Note









Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2018 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao&nbspLinLe&nbspGaoJie&nbspGanLu
Total 0.000000(s) query 5, Server time : 2018-08-16 22:28:09, Gzip enabled



题意杀。

//#include<bits/stdc++.h>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int MAXN=100;
int n,m,pre[MAXN];
struct Edge{
    int x,y,dis;
    Edge(){}
    Edge(int _x,int _y,int _dis)
    {
        x=_x; y=_y; dis=_dis;
    }
};
bool cmp(Edge a,Edge b)
{
    return a.dis<b.dis;
}
void init()
{
    for(int i=0;i<=n;i++)
        pre[i]=i;
}
int find(int x)
{
    return pre[x]==x?x:pre[x]=find(pre[x]);
}
bool join(int x,int y)
{
    x=find(x);
    y=find(y);
    if(x!=y)
    {
        pre[x]=y;
        return true;
    }
    return false;
}

vector<Edge> d;
int main()
{
    while(~scanf("%d",&n)&&n)
    {
        init();
        d.clear();
        int x,y,z;
        char ch1,ch2;
        for(int i=0;i<n-1;i++)
        {
            getchar();
            scanf("%c %d",&ch1,&m);
            x=ch1-'A';
            for(int j=0;j<m;j++)
            {
                getchar();
                scanf("%c %d",&ch2,&z);
                y=ch2-'A';
                d.push_back(Edge(x,y,z));
            }
        }
        sort(d.begin(),d.end(),cmp);
        int cnt=0,ans=0;
        for(int i=0;i<d.size();i++)
        {
            Edge e=d[i];
            if(join(e.x,e.y))
            {
                ans+=e.dis;
                cnt++;
            }
            if(cnt==n-1)    break;
        }
        printf("%d\n",ans);

    }
    return 0;
}









VOF模型求解方法:从SIMPLEC到PISO的稳定性优化策略 本文深入探讨了VOF模型求解方法中SIMPLEC与PISO算法的稳定性优化策略,重点分析了两种算法在稳态和瞬态问题中的应用差异。通过对比PRESTO离散化方法与其他格式的优劣,提供了针对多相流模拟的实用设置建议和稳定性优化技巧,帮助工程师有效提升计算效率和精度。 阅读详情

相关推荐

PLDM入门(七):FRU Data Format

每个字段为TLV(Type-Length-Value)格式,具体类型、长度范围和值定义需参考。通过条件过滤(记录句柄、类型、字段类型等)分块获取FRU记录数据(可选功能)。整个FRU数据表由多个FRU记录数据块组成,每个数据块对应表2的结构(即包含。决定,每个字段按顺序排列(Type→Length→Value)通过分块传输方式写入FRU记录表数据(需终端支持写入操作)。(文档未提供表5内容,需结合标准文档完整版)。、字段数量、编码类型及具体字段的TLV数据)。无请求数据(空请求)。

weixin_44032634的博客 1762

杭电1301--Jungle Roads(最小生成树)

Jungle Roads Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5379Accepted Submission(s): 3884 Problem Description The Head Elder of t...

weixin_34032792的博客 154

Python介绍与安装

Python介绍与安装

acegi13579的专栏 3221

杭电1301Jungle Roads

Jungle Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5421    Accepted Submission(s): 3909 Problem Description The Head

hpuzsk的博客 707

直击痛点:VS2015离线安装报错“安装包丢失或损坏”的根源分析与精准修复

本文深入剖析了Visual Studio 2015离线安装时出现“安装包丢失或损坏”报错的根本原因,指出问题核心在于安装程序固化的临时路径查找逻辑。文章提供了一步到位的精准修复方案,通过将ISO镜像中的完整packages文件夹复制到安装程序指定的临时路径,即可无需联网、无需操作证书直接解决问题,并对比分析了其他常见方法的局限性。

weixin_27734811的博客 357

Label Studio保姆级教程:从零搭建医疗影像标注平台(DICOM格式支持)

本文提供基于Label Studio从零搭建医疗影像标注平台的保姆级教程。针对DICOM格式支持,详细阐述了环境部署、DICOM深度集成与预处理、团队协作权限管理以及质量审核闭环等核心环节,旨在构建一个高效、可落地的医疗AI数据标注解决方案,助力模型落地。

nft7creator的博客 304

HDU 1301 Jungle Roads (最小生成树)kruskal

Jungle Roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4260 Accepted Submission(s): 3114 Problem Description The Head Elder of the

TIMELIMITE的专栏 591

(2)NPW(监控片)【中】---业务场景精讲

自己在日常工作当中,由于非产线人员出生,对NPW的知识一直一知半解,业务场景认识的不够透彻,做系统的时候很难理解甲方的NPW业务应用,特收集了不少关于NPW的一些业务场景,下面都是一些摘抄,大家关注我标红标粗的部分,

阿拉伯梳子的专栏 1586

hdu1102 Constructing Roads(两种基础最小生成树算法)

http://acm.hdu.edu.cn/showproblem.php?pid=1102 题意:n个村庄,给你一个矩阵代表村庄i到j的距离,求要想使所有村庄连通需要修多少长度的路。 思路:基础MST。已经给你的道路相当于这两点已经可达,那么这两点之间就不用修路,赋长度为0,对边方向性的操作同hdu1233。这一点要想清楚,不得不说图论里有些想法真的好神奇。 #in

Iguodala的博客 469

微信小程序 - 最新详细实现用户保存下载视频到手机相册,将视频临时路径、在线播放地址(网络路径)URL存储到手机,弹出访问手机相册权限询问,支持视频格式mp4、avi、mov、wmv、flv、webm

微信小程序,视频,手机相册,保存,另存为,小程序保存到相册权限,writePhotosAlbum,一键保存视频到手机相册功能(视频来源为链接),第一次要获取用户授权,授权使用相册权限,小程序视频下载,如何把视频下载到相册,下载一个视频到本地相册,显示下载进度,可取消下载,视频下载到本地,微信小程序视频如何下载,保存视频到相机,页面播放视频并下载到本地,安卓系统,苹果ios保存到相册报错,权限拒绝后打不开,添加相册授权弹框拒绝后再也出不来了,实现保存视频到手机相册功能,将mp4在线视频下载并存储到用户的手机中

🏆 前端领域优质创作者 7623

13、基于RBF的自适应鲁棒控制与反步控制方法及实现

本文介绍了基于RBF神经网络的自适应鲁棒控制与反步控制方法,详细阐述了控制系统的程序结构、核心算法及实现流程。通过Simulink搭建仿真系统,利用RBF网络逼近系统中的不确定非线性函数,并结合Lyapunov稳定性理论设计控制律,实现了对倒立摆等复杂非线性系统的高精度跟踪控制。文章还提供了完整的MATLAB/Simulink代码示例和仿真结果分析,验证了该方法的有效性与鲁棒性,为实际工程应用提供了可行的技术路径。

ol789012的博客 87

HDU 1301 Jungle Roads(裸最小生成树)

题目链接 今天做了好几个模版最小生成树。。。贴一个kurskral. 1 /* 2 HDU 1301 Jungle Roads 3 最小生成树Kurskal模版 4 */ 5 #include <stdio.h> 6 #include <string.h> 7 #include <stdlib.h> 8 int num,su...

weixin_30535913的博客 92

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

hdu 1301 Jungle Roads (最小生成树)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 思路: 题目看起来极其吓人= =!其实就是一个裸的最小生成树,把字母对应数字就可以了。 #include #include #include #include #include #include #include #include #include #include #include #i

Where amazing happens 432

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

hdu1301——Jungle Roads——最小生成树

简单地最小生成树,一A The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle overtakes roads relentlessly, so the large road network is too expensive to

WAR___NING的专栏 793

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Jungle Roads HDU - 1301 最小生成树

求地图中的最小生成树。 多组输入。每个数据第一行为图中点的个数。紧接着n-1行,每行的第一个字母为图中的某一个点,(按照字典序升序),第二个数字表示这个点与比它字典序大的相连点的个数,然后后面紧接着为相连边的情况。 当地图中点的个数为0时,输入结束。 Input 9 A 2 B 12 I 25 B 3 C 10 H 40 I 8 C 2 D 18 G 55 D 1 E 44 E 2 F 60 G 38 F 0 G 1 H 35 H 1 I 35 3 A 2 B 10 C 40 B 1 C 20 0 Out.

qq_45891413的博客 239

Jungle Roads - HDU 1301 - 最小生成树

Jungle Roads - HDU 1301 - 最小生成树  这道题和Jungle Roads - POJ 1251 - Virtual Judge完全是一道题,直接把代码复制粘贴一遍就可以了。当时被作为Kruskal算法的例题。  代码传送门:Kruskal算法简明

LucienShui 667

【最小生成树-Kruskal】HDU 1301 Jungle Roads

Jungle Roads #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <string> #include <ve...

L_X_ 208

hdu1301 Jungle Roads 【最小生成树】

Jungle Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5421    Accepted Submission(s): 3909 Problem Description The Head El

qingkong5886的博客 367

hdu1301:Jungle Roads(最小生成树)

http://acm.hdu.edu.cn/showproblem.php?pid=1301 Problem Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads betwe...

358

Hdu 1301 Jungle Roads (最小生成树)

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1301 很明显,这是一道“赤裸裸”的最小生成树的问题; 我这里采用了Kruskal算法,当然用Prim算法也一样可以解题。 #include <iostream> #include <cstring> #include <cstdio>...

weixin_30865427的博客 97

HDU1301 Jungle Roads 【最小生成树Prim】

Jungle Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4268    Accepted Submission(s): 3120 Problem Description The Head

长风的专栏 2347

HDU 1301 Jungle Roads【最小生成树,prim】

点击打开链接 题意:  给你n的城市,然后给你城市间的距离,让你花最小的代价,连通。 题解: 最小生成树 ,快结束才A 的,刚开始我看着题,坑爹的图片没显示,我就没看懂。最后突然看见好多人过了。。赶紧看看,发现了图。。。。 还有一点,就是敲prim  ,里面的括号扩错地方,,,,,,让我郁闷半天,,, #include #include #include u

zoro_n的博客 280

HDU1301 Jungle Roads(最小生成树)

Jungle Roads HERE Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extra roads between villages some years ago. But the jungle o...

qq_45739382的博客 214

HDU——1301 Jungle Roads(最小生成树问题)

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 样例: Sample Input 9 A 2 B 12 I 25 B 3 C 10 H 40 I 8 C 2 D 18 G 55 D 1 E 44 E 2 F 60 G 38 F 0 G 1 H 35 H 1 I 35 3 A 2 B 10 C 40 B 1 C 20 0 Sample Output 216 30 题意: 给定村庄数量n,一系列村庄之间的道路每月维护成本信息,让你计算出让所有村

pursuit的博客 583

POJ 1251 + HDU 1301 Jungle Roads 【最小生成树】

这是一道裸的最小生成树题,拿来练手,题目就不放了 个人理解 Prim有些类似最短路和贪心,不断找距当前点最小距离的点 Kruskal类似于并查集,不断找最小的边,如果不是一棵树的节点就合并为一颗树 AC代码: Prim算法: #include<iostream> #include<cstdio> //EOF,NULL #include<cstri...

NoobPlayer_llke的博客 270
上一篇: POJ 1789Truck History——————最小生成树
下一篇: POJ 1611 The Suspects——————并查集
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值