Cat in a tree
시간 제한: 1000ms메모리 제한: 512MB출처: BOI 2017BOJ 22199
문제
A cat lives in a tree that has N nodes. She will demarcate her territory by “marking” some of the tree nodes. Marked nodes may not be closer to each other than distance D. Find the maximum number of nodes that the cat can mark.
입력
First line has two integers, N and D. The 0’th node is the root node of the tree. Then follows N − 1 lines, the i-th of which contain a single integer xi with 0 ≤ xi < i (starting with i = 1). This means that node xi is connected to node i.
출력
Output should contain one integer: the maximum number of nodes that can be marked.
예제
예제 1
입력
4 3 0 0 1
출력
2
예제 2
입력
3 1000 0 0
출력
1
코드를 제출하려면 로그인하세요.