RXD and dividingTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 674 Accepted Submission(s): 290
Problem Description
RXD has a tree
T
, with the size of
n
. Each edge has a cost.
Define f(S) as the the cost of the minimal Steiner Tree of the set S on tree T . he wants to divide 2,3,4,5,6,…n into k parts S1,S2,S3,…Sk , where ⋃Si={2,3,…,n} and for all different i,j , we can conclude that Si⋂Sj=∅ . Then he calulates res=∑ki=1f({1}⋃Si) . He wants to maximize the res . 1≤k≤n≤106 the cost of each edge∈[1,105] Si might be empty. f(S) means that you need to choose a couple of edges on the tree to make all the points in S connected, and you need to minimize the sum of the cost of these edges. f(S) is equal to the minimal cost
Input
There are several test cases, please keep reading until EOF.
For each test case, the first line consists of 2 integer n,k , which means the number of the tree nodes , and k means the number of parts. The next n−1 lines consists of 2 integers, a,b,c , means a tree edge (a,b) with cost c . 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 n≤100 .
Output
For each test case, output an integer, which means the answer.
Sample Input
Sample Output
Source
———————————————————————————————————
题意:给一个n个节点的树,要求将2-n号节点分成k部分,然后将每一部分加上节点1,
每
一个子树的val为最小斯坦纳树,求总的最大val
其实这里的斯坦纳树很简单,就是在原树中找最少的边是的一个集合里的点全部连通
思路:比赛时在那贪心构造搞,搞了半天弄不出,赛后才发现很简单的
先贴一下官方题解:
把1看成整棵树的根. 问题相当于把2∼n每个点一个[1,k]的标号. 然后根据最小斯坦纳树的定义, (x,fax) 这条边的
贡献是 x 子树内不同标号的个数目difi. 那么显然有difi≤min(k,szi), szi表示子树大小. 可以通过构造让所有difi都
取到最大值. 所以
答案就是
∑x=2nw[x][fax]∗min(szx,k) 时间复杂度O(n).
其实很简单,要想和最大,每条边尽可能多的用,而他用的次数是这条边延伸下去的
节点数和k取一个较小值,最后把每条边的权值*用的次数累加即可
|
Hdu6060 RXD and dividing(2017多校第3场)
最新推荐文章于 2018-07-19 09:08:39 发布