← 返回 snowflake 的题目列表Minimum deletions to make tree height at most N
类型:online_judge
Problem: Minimum deletions so that the tree height is at most N
Given an undirected tree with n nodes rooted at 1, you may delete nodes (and incident edges). After deletions:
The root 1 must remain.
The remaining nodes must be connected (still a rooted tree).
The maximum depth (edges from root) must be ≤ N.
Return the minimum number of deleted nodes.
Input
n N
n-1 edges u v
Output
Minimum deletions.
Constraints
1 ≤ n ≤ 2e5
0 ≤ N ≤ n-1
Examples
See tests below.
Example
Input
5 2
1 2
1 3
3 4
4 5
Output
1