当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5102:The K-th Distance

题目描述
Given a tree, which has n node in total. Define the distance between two node u and v is the number of edge on their unique route. So we can have n(n-1)/2 numbers for all the distance, then sort the numbers in ascending order. The task is to output the sum of the first K numbers.
输入解释
There are several cases, first is the number of cases T. (There are most twenty cases).
For each case, the first line contain two integer n and K ($2 \leq n \leq 100000 , 0 \leq K \leq min(n(n-1)/2 , 10^6)$ ). In following there are n-1 lines. Each line has two integer u , v. indicate that there is an edge between node u and v.
输出解释
For each case output the answer.
输入样例
2
3 3
1 2
2 3
5 7
1 2
1 3
2 4
2 5
输出样例
4
10
来自杭电HDUOJ的附加信息
Recommend heyang

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #17

源链接: HDU-5102

最后修改于 2020-10-25T23:19:49+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
8000/4000MS(Java/Others) 65536/65536K(Java/Others)