Tree Separator
Time limit2sMemory limit512 MB
Given a tree, delete all vertices on some simple path between two chosen vertices; maximize the number of remaining components of size at least K.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, DFS, Greedy
- Solved
- No attempts yet
Problem
You are given a tree with vertices and an integer . Choose two distinct vertices and of , and let be the simple path between them. Remove every vertex on from , together with every edge that has at least one endpoint on .
Choose and so that the number of connected components with or more vertices in the remaining graph is as large as possible.
Input
The input is a single test case in the following format.
N K
u1 v1
.
.
.
uN-1 vN-1
The first line has two integers and (, ). Each of the following lines describes one edge. Line has two integers and (, ), meaning that is an edge of . The given edges form a tree.
Output
Print the maximum number of connected components with or more vertices in one line.