#P22400. Purple Crayon

Purple Crayon

题目链接

题意

已知一棵 nn 个节点的树,有红蓝两方需要对其操作。

红方先动,选择若干棵子树,将它们的每个节点都染成红色,但要保证染红的节点数不超过 kk

然后蓝方动,选择若干棵子树,将它们的每个节点都染成蓝色,但不能存在一个点染红后又染蓝。可以染的节点数无限

w,r,bw,r,b 分别表示操作完后树上没有颜色的、红色的、蓝色的点的数量,那么最后的得分是 w×(rb)w\times(r-b)

红方想让得分尽量大,蓝方想让得分尽量小。

求最后得分。

输入格式

The first line contains two integers $n$ and $k$ ($2 \le n \le 2 \cdot 10^5$; $1 \le k \le n$) — the number of vertices in the tree and the maximum number of red nodes.

Next $n - 1$ lines contains description of edges. The $i$-th line contains two space separated integers $u_i$ and $v_i$ ($1 \le u_i, v_i \le n$; $u_i \neq v_i$) — the $i$-th edge of the tree.

It's guaranteed that given edges form a tree.

Output

Print one integer — the resulting score if both Red and Blue play optimally.

Samples

4 2
1 2
1 3
1 4
1
5 2
1 2
2 3
3 4
4 5
6
7 2
1 2
1 3
4 2
3 5
6 3
6 7
4
4 1
1 2
1 3
1 4
-1

Note

In the first test case, the optimal strategy is as follows:

  • Red chooses to color the subtrees of nodes $2$ and $3$.
  • Blue chooses to color the subtree of node $4$.
At the end of this process, nodes $2$ and $3$ are red, node $4$ is blue, and node $1$ is white. The score of the game is $1 \cdot (2 - 1) = 1$.

In the second test case, the optimal strategy is as follows:

  • Red chooses to color the subtree of node $4$. This colors both nodes $4$ and $5$.
  • Blue does not have any options, so nothing is colored blue.
At the end of this process, nodes $4$ and $5$ are red, and nodes $1$, $2$ and $3$ are white. The score of the game is $3 \cdot (2 - 0) = 6$.

For the third test case:

The score of the game is $4 \cdot (2 - 1) = 4$.