P18153 [NWERC 2026] Branch Manager

Description

Bettina is a gardener tending to the trees in Karlsruhe's palace garden. The tree she is currently working on is also a tree in the mathematical sense: it has $n$ nodes numbered $1$ to $n$, where node $1$ is the point where the tree grows out of the ground. Every other node $i$ ($2\leq i\leq n$) grows from a branch that connects it downward to its parent node $p_i$ ($1\leq p_i

Input Format

The input consists of: - One line with two integers $n$ and $k$ ($2\leq n\leq 600$, $1\leq k\leq 600$), the number of nodes and the number of cuts. The nodes are numbered from $1$ to $n$. - One line with $n-1$ integers $p_2,\dots,p_n$ ($1\leq p_i

Output Format

Output the maximum possible number of nodes after $k$ cuts. Your answer should have an absolute or relative error of at most $10^{-6}$. Note that the answer can be very large, but it can be shown that it never exceeds $10^{200}$. This fits in a C, C++, or Java `double`, a Python `float`, or a Kotlin `Double`.

Explanation/Hint

### Sample 1 Explanation ![](https://cdn.luogu.com.cn/upload/image_hosting/7lzehjdi.webp) **Figure 1.** A single cutting operation, which is also an optimal solution to Sample Input 1. The cut branch is shown as dashed and in red. The regrown copies are shaded in blue. ### Sample 3 Explanation The exact answer in this case is $315\,824\,312\,111\,610\,396\,173$.