The cows have reconstructed Farmer John's farm, withits N barns (1 <= N <= 150,
number1..N) afterthe terrible earthquake last May. The cows didn't have timeto
rebuild any extra roads, so now there is exactly one way togetfrom any given barn
to any other barn. Thus, the farm transportation system can be represented as a
tree.
Farmer John wants to know how much damage another earthquake could do. He wants to
know the minimum numberof roads whose destruction would isolate a subtree of
exactly P (1 <= P <= N) barns fromtherestofthe barns.
Input
* Line 1: Two integers, N and P
* Lines 2..N: N-1 lines, eachwith two integers I and J. Node I is node J's parent in the tree of roads.
Output
A single line containing theintegerthatisthe minimum numberof roads that need
to be destroyed for a subtree of P nodes to be isolated.
Examples
Input
11 6
1 2
1 3
1 4
1 5
2 6
2 7
2 8
4 9
4 10
4 11
Hint
[A subtree with nodes (1, 2, 3, 6, 7, 8) will become isolated if roads 1-4 and 1-5
are destroyed.]
POJ-1947-Rebuilding Roads-树形dp-01背包思想POJ-1947-Rebuilding Roads-树形dp-01背包思想DescriptionInputOutputExamplesInputHintProblem DescriptionSolutionCodeDescription The cows have re...