#Lutece1585. K-median
K-median
Migrated from Lutece 1585 K-median
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
给出一个个点的树,点上有权,顶点从到编号。其中号节点为根节点,号节点的父亲为号节点。
对于树上的一个联通点集的点权组成的集合,定义中位数为:将其中的元素从小到大排序后得到 ,.....
则这个集合的中位数为.
现在问题来了,对于中的每个,从这棵树上选取联通块所能获得的最大中位数是多少呢?
Input
第一行输入一个个整数 ,分别表示树的点数.
第二行个整数,第个数表示标号为的点的权值.保证点权是到的一个排列.
Output
共一行,个整数,依次表示最大的中位数,中位数......中位数.
Samples
5
1 2 3 4 5
5 2 2 1 1
Resources
每周一题Div1