QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#33. 树上的猫

统计

一只猫住在一棵有 $N$ 个节点的树上。它将通过“标记”树中的一些节点来划分领地。被标记的节点之间的距离不得小于 $D$。请找出这只猫最多可以标记的节点数量。

CC BY-2.0, Just a kitten in a tree by Zoe Shuttleworth via Flickr

输入格式

第一行包含两个整数 $N$ 和 $D$。第 $0$ 号节点是树的根节点。接下来有 $N - 1$ 行,第 $i$ 行包含一个整数 $x_i$,满足 $0 \le x_i < i$(从 $i = 1$ 开始)。这意味着节点 $x_i$ 与节点 $i$ 相连。

数据范围

我们始终有 $1 \le N, D \le 2 \cdot 10^5$。对于子任务,输入满足以下进一步限制:

  • 子任务 1:11 分,$N \le 18$
  • 子任务 2:40 分,$N \le 1\,500$
  • 子任务 3:49 分,无其他限制。

输出格式

输出应包含一个整数:可以标记的最大节点数量。

样例

输入 1

4 3
0
0
1

输出 1

2

输入 2

3 1000
0
0

输出 2

1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.