博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU_5723_最小生成树+任意两点距离的期望
阅读量:6614 次
发布时间:2019-06-24

本文共 2015 字,大约阅读时间需要 6 分钟。

Abandoned country

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 3449    Accepted Submission(s): 846

Problem DescriptionAn abandoned country has
n(n100000)villages which are numbered from 1 to n . Since abandoned for a long time, the roads need to be re-built. There are m(m1000000) roads to be re-built, the length of each road is wi(wi1000000) . Guaranteed that any two w are different. The roads made all the villages connected directly or indirectly before destroyed. Every road will cost the same value of its length to rebuild. The king wants to use the minimum cost to make all the villages connected with each other directly or indirectly. After the roads are re-built, the king asks a men as messenger. The king will select any two different points as starting point or the destination with the same probability. Now the king asks you to tell him the minimum cost and the minimum expectations length the messenger will walk.
 

 

InputThe first line contains an integer
T(T10) which indicates the number of test cases. 
For each test case, the first line contains two integers n,indicate the number of villages and the number of roads to be re-built. Next m lines, each line have three number i,j,w , the length of a road connecting the village i and the village j is w .
 

 

Output
output the minimum cost and minimum Expectations with two decimal places. They separated by a space.
 

 

Sample Input
1
4 6
1 2 1
2 3 2
3 4 3
4 1 4
1 3 5
2 4 6
 

题意:求最小生成树,再求任意两点距离的期望。

最小生成树用kruscal。期望一开始不会求,看题解发现使用dfs:分别求每条边的贡献,一条边的贡献等于这条边的|左子树|*|右子树|*value。

 

代码中使用pair和vector

#include
#include
#include
#include
#include
using namespace std;struct Path{ int x,y; double value;} path[1000005];typedef pair
P;vector

edge[1000005];bool cmp(Path a,Path b){ return a.value

 

Sample Output
6 3.33
 

 

Author
HIT
 

 

Source

转载于:https://www.cnblogs.com/jasonlixuetao/p/5702215.html

你可能感兴趣的文章
飞机维修领域,RFID技术作用巨大
查看>>
Slack 是如何变成史上增长最逆天的企业级应用的?
查看>>
十分简单的redis使用说明及性能测试
查看>>
乱象丛生的IDC行业,冒然闯入必将铩羽而归
查看>>
Intel仍有黑科技 硅光学芯片正朝400Gbps迈进
查看>>
早定年夜饭 中华通网络电话来帮忙
查看>>
《Python编程实战:运用设计模式、并发和程序库创建高质量程序》—— 2.1 适配器模式...
查看>>
以大数据为支撑勾勒体育产业蓝图
查看>>
数据资产的运营商--天市大数据交易平台
查看>>
中小企业如何成功转型跨境电商
查看>>
《UNIX网络编程 卷1:套接字联网API(第3版)》——8.8 验证接收到的响应
查看>>
java中文乱码解决之道(二)—–字符编码详解:基础知识 + ASCII + GB**
查看>>
《ANTLR 4权威指南》——2.5 语法分析树监听器和访问器
查看>>
02_JNI中Java代码调用C代码,Android中使用log库打印日志,javah命令的使用,Android.mk文件的编写,交叉编译...
查看>>
IE 将支持 HSTS 安全机制
查看>>
《沟通的技术——让交流、会议与演讲更有效》一导读
查看>>
TIOBE 2016 年 5 月编程语言排行榜:Ruby 排名创历史新高
查看>>
《异构信息网络挖掘: 原理和方法(1)》一第1章 引言
查看>>
8 种提升 ASP.NET Web API 性能的方法 【已翻译100%】
查看>>
《Node.js区块链开发》——1.5 总结
查看>>