Under construction

Still being built. Things may change

Trimming the Tree

Interview

Time limit1sMemory limit1024 MB

Summary
Given a tree rooted at node 1 and a limit K per level, remove subtrees so that each level keeps at most K nodes, and find the maximum number of nodes kept.
Level

Medium5 of 10

Topics
Greedy, Tree, BFS, Sorting
Solved
No attempts yet

Problem

In the country where Dongbin lives, trees are shaped like trees.

As Christmas approaches, Dongbin decides to trim a tree and decorate it at home.

Dongbin's tree has N nodes connected by N-1 edges. Nodes are numbered from 1 to N, and the root node is 1.

In the tree, the root has level 0, and the level increases by 1 with each step down. Dongbin wants to decorate every node, but if the thickness of the tree exceeds K, the tree does not fit in the house.

Here, the thickness of the tree is the maximum number of nodes on the same level.

In the end, some nodes must be removed so that the thickness is at most K. When a parent node is removed, all of its child nodes are removed too.

Dongbin wants as many decorations as possible, so he wants to keep as many nodes as possible. Help Dongbin.

Input

The first line contains the number of vertices N and the maximum number of nodes K that can be kept on each level. (1 ≤ N ≤ 10,000, 1 ≤ K ≤ N)

Each of the next N-1 lines contains two integers a**i and bi. This means node ai and node bi are connected by an edge. (1 ≤ ai, bi ≤ N, ai ≠ bi)

Output

Print the number of nodes that remain after trimming the tree while keeping as many nodes as possible.

Examples2

  1. Example 1

    Input
    5 2
    1 3
    1 4
    1 5
    5 2
    
    Expected output
    4
    
  2. Example 2

    Input
    10 2
    2 8
    5 1
    10 5
    3 5
    6 3
    8 7
    2 5
    3 4
    9 6
    
    Expected output
    8