杭电-1301Jungle 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): 5825    Accepted Submission(s): 4206


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
 

简单的最小生成树



#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
	int x,y,dis;
}s[100000];
int n,m,per[100]; 
bool cmp(node x,node y)
{
	return x.dis<y.dis;
}
void init()
{
	for(int i=1;i<=n;i++)
	per[i]=i;
}
int find(int x)
{
	while(x!=per[x])
	x=per[x];
	return x;
}
bool join(int x,int y)
{
	int fx=find(x),fy=find(y);
	if(fx!=fy)
	{
		per[fx]=fy;
		return true;
	}
	return false;
}
int main() 
{
	int a,b,i,j;
	char c,d;
	while(scanf("%d",&n),n)
	{
		getchar();
		init();
		int t=0;
		for(i=0;i<n-1;i++)
		{
			scanf("%c",&c);
			scanf("%d",&a);
			getchar();
			for(j=0;j<a;j++)
			{
				scanf("%c %d",&d,&b); 
				getchar();
				s[t].x=c-'A'+1;
				s[t].y=d-'A'+1;
				s[t++].dis=b;
			}
		}
		sort(s,s+t,cmp);
		int sum=0;
		for(i=0;i<t;i++)
		{
			if(join(s[i].x,s[i].y))
			sum+=s[i].dis;
		}
		printf("%d\n",sum);
	}
	return 0;
}





《供应链金融风控模型设计:多维度数据整合与动态风险预警机制》 注:方案突出供应链金融「三流合一」(资金流、物流、信息流)的风控逻辑,通过多维度数据整合与动态预警,解决传统风控中中小企业信用评估难、链条风险传导监测滞后的问题。◦ 构建供应链拓扑图,计算「核心企业违约对上下游企业的影响系数」(如某电子厂商违约时,其前五大供应商的风险权重自动提升40%)• 区块链应用:将核心企业应付账款上链存证,防止「一票多融」欺诈(如某供应商用同一应收账款在多家银行融资)◦ 财务数据:核心企业审计报告、上下游企业纳税数据(增值税发票频次/金额) 阅读详情

相关推荐

Zemax光机热集成分析:从FEA数据导入到光学性能评估实战

在精密光学系统设计中,环境温度变化和机械应力是导致像质恶化的关键因素,这涉及到光、机、热多物理场的耦合分析。其核心原理在于,通过有限元分析(FEA)软件(如ANSYS)模拟热与力学载荷下的结构变形和温度分布,并将这些物理场数据精准映射到光学设计软件(如Zemax)中,以评估其对调制传递函数(MTF)、点列图等核心光学指标的影响。这项技术的工程价值在于,它使设计从静态的理想模型跃升至动态的工程现实,能够在设计阶段就预测并补偿环境扰动,从而显著提升光学系统在航空航天、车载镜头、高功率激光等严苛工况下的可靠性与稳

weixin_30565327的博客 356

hdu 1301 Jungle Roads(Prim算法)

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 overt

w1025758212的博客 310

计量经济学(因果关系探究-空间双重差分模型: 破解空间溢出效应的因果分析工具)

本文介绍了传统双重差分(DID)模型及其局限性,重点阐述了空间DID模型的必要性。传统DID通过组间差分分离干预效应,但无法处理空间溢出效应。空间DID模型引入空间计量方法,包括三种类型:空间自回归模型(SDID-SAR)捕捉因变量溢出,空间误差模型(SDID-SEM)处理残差相关性,空间杜宾模型(SDID-SDM)同时考虑因变量和自变量的空间滞后。模型选择需结合空间相关性检验,适用于环境政策、房地产限购等存在空间交互效应的研究场景。

YBAdvanceFu的博客 2030

杭电-1301 Jungle Roads (kruskal)

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

lu_1110的博客 268

Gerrit 使用操作手册

Gerrit是一种免费、开源的代码审查工具,使用网页交互页面。这个软件的名称来自于荷兰设计师师赫里特·里特费尔德(GerritRietveld),作者为Google公司的ShawnPearce。它使用Git作为底层版本控制系统,相比于其他的代码管理工具,Gerrit明显的特色是代码审核。利用网页浏览器,同一个团队的软件程序员,可以相互审核(Review)彼此修改后的程序代码,然后决定是继续提交还是取消提交。...

九离的博客 1万+

ffmpeg 4.4 cenc-aes-ctr 加解密 MP4 工程性质分析

ffmpeg 4.4 cenc-aes-ctr 加解密 MP4 工程性质分析

Dream_Dynasty的博客 3045

杭电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

《实战指南 | MES业务顾问蓝图设计方案:避免90%项目踩坑,从战略到落地的全攻略》

《MES业务顾问蓝图设计方案》干货分享:制造业高管常遇MES系统沦为"摆设"的困境,根源在于蓝图设计阶段未抓准业务痛点。本文系统梳理了6大关键点:1)战略定位上承ERP下接设备;2)通过现场蹲点挖掘真实需求;3)构建可扩展技术架构;4)建立数据闭环管理;5)组织保障分步实施;6)持续量化KPI优化。方案强调从业务价值出发,避免"纸上谈兵",通过数据驱动实现"计划-执行-反馈"闭环,最终让MES成为企业数字化的核心资产。

「东哥说MES」 专注于MES制造执行系统,为你拆解核心架构、功能模块及与ERP/PLC的集成逻辑。提供从入门到精通的系列干货、精选行业报告与实用工具,构建你的数字化知识体系,关注我,用实战经验照亮你的数字化之路。 1334

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

Jungle RoadsTime Limit: 2000/1000 MS (Java/Others)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10014&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Accepted Submission(s): 734

鸿杰 的博客 325

Apache Flink连载(一):Apache Flink是什么?

Apache Flink 是一个框架和分布式处理引擎,用于在。

qq_32020645的博客 1216

【AI智能体】Codex 高级进阶使用技巧项目实战操作详解

Codex 高级进阶使用技巧项目实战操作详解

congge 1万+

杭电10301-Jungle Roads(最小生成树问题)

在昨天的实验室周六比赛的时候第一次看到这道题目,就看了一眼图就果断想放弃。直到最后里结束还有一个小时,发现实在无题可做,最后泽成大佬研究了几分钟竟然一A,后来问了吴挺成是什么类型的题目,竟然说是什么最小生成树,当时一脸懵逼,这tm是什么jb鬼东西...........一听名字就搞不来,但还是去问了一下题意(懒得看题目了),突然发现这和杭电的畅通类型的题目有点像啊!!        

mcu旺仔acm的博客 503

(11-3-01 )

以太坊(Ethereum)是一种基于区块链技术的开源平台和加密货币。它于2015年由Vitalik Buterin和Gavin Wood等开发者创建,并成为比特币之后最受欢迎的加密货币之一。以太坊不仅支持加密货币交易,还为开发者和企业提供了构建去中心化应用程序的强大工具。在本节的内容中,将实型一个完整的机器学习模型项目,智能检测出以太坊区块链中的非法账户。从问题定义到模型建立和评估,再到最终的总结和建议。本实例突出了处理类别不平衡问题的重要性,并展示了如何使用多种机器学习算法来解决实际问题。此外,通过数据可

码农三叔 2169

杭电 1301 Jungle Roads 【最小生成树&&Kruskal】

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

巧克力华夫脆 428

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

杭电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...

dixi7825的博客 156

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

hdoj-1301 Jungle Roads 【最小生成树】

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1301        题目可长 而且还是英文  没必要一字一句的去读题  可以根据下面的输入输出和图来搞清题意

Just do it 676

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

【POJ】[1251]Jungle Roads

知道是最小生成树 都懒得再一句一句翻译题目了……由题目描述 这里用Prim更好一些 因为村庄数比较少

BoilTask Talk Show 631

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

杭电 1301 junjle road(最小生成树)

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 overt

不为自己找借口的博客 366

杭电ACM1301——Jungle Roads~~最小生成树

这题,简单的最小生成树问题。 只是输入的时候比较麻烦,一开始的N,是村庄的个数,下面N - 1 条信息,一开始的大写字母S和数K,是S村庄有K条路连接,后面是K个村庄以及权值。 处理好了输入的数据,就很简单了。 下面的是AC的代码: #include #include #include #include using namespace std; class data { publ

XD 938

杭电1018-Big Number(大数)

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 31165    Accepted Submission(s): 14464 Problem Description In ma

Eric_keke的专栏 2126

杭电1242-Rescue(bfs+优先队列||队列)

Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 21824    Accepted Submission(s): 7776 Problem Description Angel was ca

Eric_keke的专栏 1581

杭电1097-A hard puzzle(快速幂)

A hard puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 35177    Accepted Submission(s): 12627 Problem Description lcy give

Eric_keke的专栏 1572

杭电1000- A+B Problem

A + B Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 499575    Accepted Submission(s): 158358 Problem Description Calc

Eric_keke的专栏 1485

杭电-1034Candy Sharing Game(模拟)

Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4434    Accepted Submission(s): 2705 Problem Description A numbe

Eric_keke的专栏 1349

杭电find the safest road(最短路径,dijkstra,floyd)

find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 9502    Accepted Submission(s): 3360 Problem Description

Eric_keke的专栏 1201
上一篇: 杭电-1102Constructing Roads(最小生成树)
下一篇: 杭电-1159Common Subsequence(LCS)
Eric_keke
博客等级 码龄12年 37粉丝 221原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值