Thakurs tree game

Thakurs tree game

Time Limit: 2.0 s

Memory Limit: 512.0 MB

Description

Thakur is playing a game in a tree of \(N\) nodes. In this game he starts from a node and wants to visit as many nodes as possible. All nodes are connected by at least one single path.

Thakur visits each node once but he can visit at max \(K\) nodes twice. He can not visit any node more than twice in any condition.
You have to tell how many different nodes can Thakur visit if he starts from node 1.

Input

First line takes two integer \(N,K\) : number of nodes and maximum number of nodes he can visit twice
Next \(N-1\) line takes two integer \(u,v\) : which means there is an edge between node \(u\) and \(v\)

\(1 <= N <= 2*10^5\)
\(0 <= K <= 100\)
\(1 <= u,v <= N\)
it is guaranteed that the input makes a tree.

Output

One integer, the maximum number of nodes Thakur can visit.

Sample

Input Output

6 3
1 2
1 3
2 4
3 5
3 6

6

6 2
1 2
1 3
2 4
3 5
3 6

5

In testcase 1:
thakur visits nodes by 1 -> 2 -> 4 -> 2 -> 1 -> 3 -> 5 -> 3 -> 6
he visits node 1,2,3 twice

in testcase 2:
thakur visits nodes by 1 -> 2 -> 1 -> 3 -> 5 -> 3 -> 6
he visits node 1,3 twice

Information

ID
1111
Difficulty
8
Category
(None)
Tags
# Submissions
40
Accepted
1
Accepted Ratio
2%
Uploaded By

Related

In following contests:

Brain Booster #7