QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#7961. A Tree

统计

You are given a tree, which is an undirected connected graph consisting of $n$ nodes and $n-1$ edges.

Each node is initially white. You must color exactly $k$ nodes black. The weight of an edge is defined as the absolute difference between the number of black nodes in the two connected components formed by removing that edge. The weight of the tree is defined as the sum of the weights of all edges. You need to minimize the total weight of the tree.

Input

The first line contains two positive integers $n$ and $k$ ($1 \leq k \leq n \leq 5 \times 10^5$).

The next $n-1$ lines each contain two positive integers $x$ and $y$, representing an edge in the tree.

Output

Output a single line containing the minimum total weight of the tree under the optimal coloring scheme.

Examples

Input 1

10 4
1 2
2 3
2 4
3 5
3 6
3 7
4 10
6 8
8 9

Output 1

16

Note 1

The figure below shows one such coloring scheme that satisfies the conditions, where the numbers on the edges represent the edge weights.

img

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.