QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#7961. 一棵树

统计

题目描述

这里有一棵树,具体的,这是一张有 $n$ 个节点和 $n-1$ 条边组成的无向联通图。

每个节点初始颜色为白色,你需要恰好将其中 $k$ 个节点染成黑色,定义一条边的权值是,断开这条边之后,两个连通块的黑色节点个数之差,定义一棵树的权值为所有边的权值求和,你需要最小化整棵树的权值。

输入格式

第一行两个正整数 $n,k$($1\leq k\leq n\leq 5\times10^5$)。

接下来 $n-1$ 行,每行两个正整数 $x,y$ 表示树上的一条边。

输出格式

输出共 $1$ 行,表示最优的染色方案下,这棵树的权值的最小值。

样例1输入

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

样例1输出

16

样例1解释

下图展示了一种满足条件的染色方案,边上的数字表示边权。

img

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.