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

建议使用的浏览器:

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

6065:RXD, tree and sequence

题目描述
RXD has a rooted tree $T$ with size $n$, the root ID is $1$, with the depth of $1$
RXD has a permutation $P$ with size $n$.
RXD wants to divide the permutaion into $k$ continuous parts
For each part, he would calculate the depth of the least common ancestor of the part. And finally accumulate them.
He wants to make the final result minimized.
Please calculate the minimal answer.
$1\leq k\leq n\leq 3\times 10^5, n\times k\leq 3\times 10^5$
输入解释
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 the size of the permutaion, and $k$ means the number of parts.
The next line consists of $n$ different integers, which means the permutation $P$.
The next $n - 1$ lines consists of 2 integers, $a, b$, means a tree edge.
It is guaranteed that the edges would form a tree.
There are 6 test cases.
输出解释
For each test case, output an integer, which means the answer.
输入样例
6 3
4 6 2 5 1 3
1 2
2 3
3 4
4 5
4 6
输出样例
6
来自杭电HDUOJ的附加信息
Recommend liuyiding

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

源链接: HDU-6065

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

共提交 0

通过率 --%
时间上限 内存上限
6000/3000MS(Java/Others) 524288/524288K(Java/Others)