博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU - 4424 Conquer a New Region
阅读量:4692 次
发布时间:2019-06-09

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

题目大意:n个点的树,i点到j点的路径最大价值是i到j点的路的权值最小值,以一个点为源点,使得从这个点到其他点的总价值最大

具体思路:贪心

先给边排序,按边权从大到小考虑是从哪个联通块做到哪个联通块

AC代码

#include
#define int long longusing namespace std;int n,a[500000],b[500000],fa[500000],sum[500000],ans[500000];pair
e[500000];int ask(int x){ if(fa[x]==x)return x;else return fa[x]=ask(fa[x]);}main(){ while(~scanf("%lld",&n)) { for (int i=1;i
=1;i--) { int fx=ask(a[e[i].second]),fy=ask(b[e[i].second]); if(ans[fx]+sum[fy]*e[i].first>ans[fy]+sum[fx]*e[i].first)fa[fy]=fx,sum[fx]+=sum[fy],ans[fx]=ans[fx]+sum[fy]*e[i].first; else fa[fx]=fy,sum[fy]+=sum[fx],ans[fy]=ans[fy]+sum[fx]*e[i].first; } printf("%lld\n",ans[ask(n)]); } return 0;}

 

转载于:https://www.cnblogs.com/Orange-User/p/7757986.html

你可能感兴趣的文章
Android创建文件夹及文件并写入数据
查看>>
file的getPath getAbsolutePath和getCanonicalPath的不同
查看>>
课时4—切入切出动画
查看>>
eclipse 编辑 python 中文乱码的解决方案
查看>>
Python 爬虫的集中简单方式
查看>>
数据库MySQL/mariadb知识点——触发器
查看>>
Ubuntu做Tomcat服务:insserv: warning: script 'tomcat' missing LSB tags and overrides
查看>>
Binary Agents
查看>>
入门Webpack,看这篇就够了
查看>>
短信拦截马”黑色产业链与溯源取证研究
查看>>
Mac Xdebug安装时遇到了Zend Engine API 不一致的问题
查看>>
最小公倍数
查看>>
asp.net如何定时执行任务
查看>>
在github上实现页面托管预览功能
查看>>
css选择器
查看>>
prim
查看>>
给陌生人写一封信
查看>>
noip2013花匠
查看>>
[CF]Equalize Them All
查看>>
React Ant design table表单与pagination分页配置
查看>>