hdu 6060 RXD and dividing (贪心)
来源:互联网 发布:linux重启命令 编辑:程序博客网 时间:2024/06/05 22:58
RXD has a tree T T, with the size of n n. Each edge has a cost.
Definef(S) f(S) as the the cost of the minimal Steiner Tree of the set S S on tree T T.
he wants to divide2,3,4,5,6,…n 2,3,4,5,6,…n into k k parts S1,S2,S3,…Sk S1,S2,S3,…Sk,
where⋃Si={2,3,…,n} ⋃Si={2,3,…,n} and for all different i,j i,j , we can conclude that Si⋂Sj=∅ Si⋂Sj=∅.
Then he calulatesres=∑ki=1f({1}⋃Si) res=∑i=1kf({1}⋃Si).
He wants to maximize theres res.
1≤k≤n≤106 1≤k≤n≤106
the cost of each edge∈[1,105] the cost of each edge∈[1,105]
Si Si might be empty.
f(S) f(S) means that you need to choose a couple of edges on the tree to make all the points in S S connected, and you need to minimize the sum of the cost of these edges. f(S) f(S) is equal to the minimal cost
Define
he wants to divide
where
Then he calulates
He wants to maximize the
For each test case, the first line consists of 2 integer
The next
It is guaranteed that the edges would form a tree.
There are 4 big test cases and 50 small test cases.
small test case means
5 41 2 32 3 42 4 52 5 6
27
给你一个树n个数,分成m组,每组的最小生成树权值加起来的总和最小
其实是个水题。。队友想复杂了。。(都想到拓扑了)。最后自己出坑发现正确思路还是很开心的
(ε=ε=ε=┏(゜ロ゜;)┛逃 算每个点能用的次数 和k比较 取小的,就是能用的点尽可能贡献
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 1e6+100;int sze[N];typedef pair<int,ll> P;vector<P> e[N];int n,m;ll ans=0;void dfs(int x,int y,ll w){sze[x]=1;for(int i=0;i<e[x].size();i++){if(e[x][i].first==y) continue;dfs(e[x][i].first,x,e[x][i].second);sze[x]+=sze[e[x][i].first];}ans+=1LL*min(sze[x],m)*w;}int main(){while(scanf("%d%d",&n,&m)!=EOF){ans=0;for(int i=1;i<=n;i++)e[i].clear();for(int i=1;i<n;i++){int a,b;ll c;scanf("%d%d%lld",&a,&b,&c);e[a].push_back(P(b,c));e[b].push_back(P(a,c));}dfs(1,0,0);printf("%lld\n",ans );}}
阅读全文
0 0
- hdu 6060 RXD and dividing (贪心)
- HDU 6060 RXD and dividing(贪心,思维)
- hdu 6060 RXD and dividing (树 + 贪心)
- HDU 6060 RXD and dividing(树形DP+贪心)
- HDU 6060 RXD and dividing(思维)
- RXD and dividing(HDU 6060)
- hdu 6060 RXD and dividing (dfs)
- HDU 6060 RXD and dividing
- HDU 6060 RXD and dividing
- [HDU]-6060 RXD and dividing
- HDU 6060 RXD and dividing
- HDU-6060 RXD and dividing
- HDU 6060 RXD and dividing
- hdu 6060 RXD and dividing
- HDU 6060 RXD and dividing
- hdu--6060-RXD and dividing
- HDU 6060 RXD and dividing
- hdu-6060-RXD and dividing
- xshell远程连接Ubuntu配置
- 小结 | 指针、数组和指针@_@
- JavaScript-数组的方法
- 两个文件的相对路径
- UCOSii任务就绪表之OSUnMapTbl[16*16]的数组是如何得到的
- hdu 6060 RXD and dividing (贪心)
- Tensorflow学习笔记(4)-mnist(MultilayerConvolutionalNetwork)
- Linux /etc/passwd文件的分析
- GCC4.8源码安装
- Log4j使用配置记录
- 二分查找及其变化应用
- hibernate测试框架整合出现的问题
- Nginx 反向代理集群 & 负载均衡(Tomcat,Jetty集群)
- 从零开始写一个jquery日历插件(一)