Tree Coloring
Limits: 3 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Given a tree with \(n\) vertices.
Zenyk wants to color it in exactly \(k\) colors such that the maximum distance between vertices of the same color is minimized.
Help him — find what this maximum distance will be in the optimal coloring.
Input
The first line contains two integers \(n\) and \(k\) — the number of vertices in the tree and the number of colors.
The following \(n - 1\) lines specify pairs of integers \(a_i\), \(b_i\) — the edges of the tree.
Output
In a single line, output an integer — the answer to the problem.
Constraints
\(1 \le n \le 10^5\),
\(1 \le k \le n\),
\(1 \le a_i, b_i \le 10^5\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 8 3 1 2 2 3 3 4 4 5 1 6 6 7 1 8 | 2 |
Source: NextGen Contest 1
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|