CF842E.Nikita and game

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Nikita plays a new computer game. There are m levels in this game. In the beginning of each level a new class appears in the game; this class is a child-class of the class y__i (and y__i is called parent-class for this new class). Thus, the classes form a tree. Initially there is only one class with index 1.

Changing the class to its neighbour (child-class or parent-class) in the tree costs 1 coin. You can not change the class back. The cost of changing the class a to the class b is equal to the total cost of class changes on the path from a to b in the class tree.

Suppose that at i -th level the maximum cost of changing one class to another is x. For each level output the number of classes such that for each of these classes there exists some other class y, and the distance from this class to y is exactly x.

尼基塔正在玩一款新的电脑游戏。这款游戏共有 mm 个关卡。在每一关开始时,游戏中会生成一个新类;该新类是类 yiy_i 的子类(此时称 yiy_i 为该新类的父类)。因此,所有类构成一棵树。初始时仅存在一个编号为 1 的类。

在类树中,将当前类切换至其相邻类(即子类或父类)需花费 1 枚金币。你不能将类切回上一状态。将类 aa 切换至类 bb 的总花费,等于类树中从 aa 到 bb 路径上所有相邻切换操作的花费之和(即路径长度)。

假设在第 ii 关中,任意两个类之间切换的最大花费为 xx。对每一关,请输出满足如下条件的类的数量:对其中每一个类,均存在另一个类 yy,使得该类到 yy 的距离恰好等于 xx。

输入格式

First line contains one integer number m — number of queries (1 ≤ m ≤ 3·105).

Next m lines contain description of queries. i -th line (1 ≤ i ≤ m) describes the i -th level and contains an integer y__i — the index of the parent-class of class with index i + 1 (1 ≤ y__i ≤ i).

第一行包含一个整数 $ m $ —— 查询的数量($ 1 \leq m \leq 3 \cdot 10^5 $)。

接下来的 $ m $ 行描述这些查询。第 $ i $ 行($ 1 \leq i \leq m $)描述第 $ i $ 层,包含一个整数 $ y_i $ —— 表示索引为 $ i+1 $ 的类的父类的索引($ 1 \leq y_i \leq i $)。

输出格式

Suppose that at i -th level the maximum cost of changing one class to another is x. For each level output the number of classes such that for each of these classes there exists some other class y, and the distance from this class to y is exactly x.

假设在第 ii 层中,将一个类别变更为另一个类别的最大代价为 xx。对每一层,输出满足如下条件的类别数量:对于其中每个类别,均存在某个其他类别 yy,使得该类别到 yy 的距离恰好为 xx。

输入输出样例

  • 输入#1

    4
    1
    1
    2
    1

    输出#1

    2
    2
    2
    3
  • 输入#2

    4
    1
    1
    2
    3

    输出#2

    2
    2
    2
    2

输入解题思路,AI测评打分。不知道怎么写?

首页