1698.
RXD, tree and sequence
时间限制 3000 ms
内存限制 512 MB
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$
输入数据
输出数据
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
· \n
· · · · · \n
· \n
· \n
· \n
· \n
· \n