#P6574. [BalticOI 2017] Cat in a tree
[BalticOI 2017] Cat in a tree
Description
A kitten is on a tree with nodes. It marks nodes to divide its territory.
The nodes it marks must have pairwise distance at least .
The distance between two nodes is the number of edges on the path between them.
Find the maximum number of nodes the kitten can mark.
Input Format
The first line contains two integers: the number of nodes and the minimum required distance between marked nodes.
Node is the root, and the nodes are numbered from to .
The next lines describe the edges. The -th line contains one number , meaning that node is connected to node .
Output Format
Output one integer: the maximum number of nodes the kitten can mark.
4 3
0
0
1
2
3 1000
0
0
1
Hint
Constraints and Notes
This problem uses bundled testdata.
- Subtask 1 (11 pts): .
- Subtask 2 (40 pts): .
- Subtask 3 (49 pts): no special constraints.
For of the testdata, , .
Explanation
Translated from BOI 2017 D2 T1 Cat in a tree.
Translator: @一只书虫仔。
Translated by ChatGPT 5
京公网安备 11011102002149号