RXD, tree and sequence

TimeLimit:3000MS  MemoryLimit:524288KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
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$
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 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.
Output
For each test case, output an integer, which means the answer.
SampleInput
6 3
4 6 2 5 1 3
1 2
2 3
3 4
4 5
4 6
SampleOutput
6
Submit
题目统计信息详细
总AC数2
通过人数2
尝试人数2
总提交量2
AC率100.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: