Jogging - MarisaOJ: Marisa Online Judge

Jogging

Time limit: 1000 ms
Memory limit: 256 MB
Given a tree of $n$ vertices rooted at $1$. Marisa have a plan to go jogging for $k$ days. Every day, she will choose a different destination and start her exercise from $1$. The distance from $u$ to $v$ is the number of edges in the shortest path between $u$ and $v$. To keep fit, she wants to maximize the total distance in $k$ days. Help her find the maximum possible distance. ### Input - The first line contains 2 integers $n,k$. - The next $n - 1$ lines, each line contains 2 integers $u, v$, there is an edge between $u$ and $v$. ### Output - Print a single integer, the maximum distance. ### Constraints - $1 \le k \le n \le 10^5$. - $1 \le u, v \le n$. ### Example Input: ``` 6 3 1 2 2 3 2 4 2 5 3 6 ``` Output: ``` 7 ``` #### Note: Marisa can choose $4, 5, 6$, and their distance to $1$ is $2, 2, 3$ respectively.