Codeforces Global Round 18
E
Purple Crayon
Codeforces
2400
原题
← DF →
翻译中…

Two players, Red and Blue, are at it again, and this time they're playing with crayons! The mischievous duo is now vandalizing a rooted tree, by coloring the nodes while playing their favorite game.

翻译中…

The game works as follows: there is a tree of size $n$, rooted at node $1$, where each node is initially white. Red and Blue get one turn each. Red goes first.

翻译中…

In Red's turn, he can do the following operation any number of times:

翻译中…
  • Pick any subtree of the rooted tree, and color every node in the subtree red.
翻译中…

However, to make the game fair, Red is only allowed to color $k$ nodes of the tree. In other words, after Red's turn, at most $k$ of the nodes can be colored red.

翻译中…

Then, it's Blue's turn. Blue can do the following operation any number of times:

翻译中…
  • Pick any subtree of the rooted tree, and color every node in the subtree blue. However, he's not allowed to choose a subtree that contains a node already colored red, as that would make the node purple and no one likes purple crayon.
翻译中…

Note: there's no restriction on the number of nodes Blue can color, as long as he doesn't color a node that Red has already colored.

翻译中…

After the two turns, the score of the game is determined as follows: let $w$ be the number of white nodes, $r$ be the number of red nodes, and $b$ be the number of blue nodes. The score of the game is $w \cdot (r - b)$.

翻译中…

Red wants to maximize this score, and Blue wants to minimize it. If both players play optimally, what will the final score of the game be?

翻译中…

Input

翻译中…

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.

翻译中…

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:

翻译中…

image

翻译中…

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

翻译中…

样例

Input #1
4 2
1 2
1 3
1 4
Output #1
1
InputCopy OutputCopy
Input #2
5 2
1 2
2 3
3 4
4 5
Output #2
6
InputCopy OutputCopy
Input #3
7 2
1 2
1 3
4 2
3 5
6 3
6 7
Output #3
4
InputCopy OutputCopy
Input #4
4 1
1 2
1 3
1 4
Output #4
-1
InputCopy OutputCopy
题目信息
题号
1615E
时间限制
2 s
内存限制
256 MB
标签
数据结构
DFS 及类似
博弈论
图论
贪心
数学
排序
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。