Thakurs tree game

Thakurs tree game

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

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

Brain Booster #7

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
8
Start at
2024-11-05 14:30
End at
2024-11-05 16:45
Duration
2.2 hour(s)
Host
Partic.
142