QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 32 MB Total points: 100

#22499. Cow Calisthenics

Statistics

Farmer John continues his never-ending quest to keep the cows fit by having them exercise on various cow paths that run through the pastures. These cow paths can be represented as a set of vertices connected with bidirectional edges so that each pair of vertices has exactly one simple path between them. In the abstract, their layout bears a remarkable resemblance to a tree. Surprisingly, each edge (as it winds its way through the pastures) has the same length.

For any given set of cow paths, the canny cows calculate the longest possible distance between any pair of vertices on the set of cowpaths and call it the pathlength. If they think this pathlength is too large, they simply refuse to exercise at all.

Farmer John has mapped the paths and found $V$ ($2 \le V \le 100,000$) vertices, conveniently numbered from $1..V$. In order to make shorter cowpaths, he can block the path between any two vertices, thus creating more sets of cow paths while reducing the pathlength of both cowpath sets.

Starting from a single completely connected set of paths (which have the properties of a tree), FJ can block $S$ ($1 \le S \le V-1$) paths, creating $S+1$ sets of paths. Your goal is to compute the best paths he can create so that the largest pathlength of all those sets is minimized.

Farmer John has a list of all $V-1$ edges in his tree, each described by the two vertices $A_{i}$ ($1 \le A_i \le V$) and $B_{i}$ ($1 \le B_i \le V$; $A_i \ne B_i$) that it connects.

Consider this rather linear cowpath set (a tree with 7 vertices):

                   1---2---3---4---5---6---7

If FJ can block two paths, he might choose them to make a map like this:

1---2 | 3---4 | 5---6---7

where the longest pathlength is 2, which would be the answer in this case. He can do no better than this.

TIME LIMIT: 2 seconds

MEMORY LIMIT: 32 MB

Input

  • Line 1: Two space separated integers: $V$ and $S$

  • Lines $2..V$: Two space separated integers: $A_{i}$ and $B_{i}$

Output

  • Line 1: A single integer that is the best maximum pathlength FJ can achieve with $S$ blocks

Examples

Input 1

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

Output 1

2

Problem credits: Michael Cohen, 2010

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.