CF842E.Nikita and game

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Nikita plays a new computer game. There are mm 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 yiy_{i} (and yiy_{i} is called parent-class for this new class). Thus, the classes form a tree. Initially there is only one class with index 11 .

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

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

输入格式

First line contains one integer number mm — number of queries ( 1<=m<=31051<=m<=3·10^{5} ).

Next mm lines contain description of queries. ii -th line ( 1<=i<=m1<=i<=m ) describes the ii -th level and contains an integer yiy_{i} — the index of the parent-class of class with index i+1i+1 ( 1<=yi<=i1<=y_{i}<=i ).

输出格式

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

输入输出样例

  • 输入#1

    4
    1
    1
    2
    1
    

    输出#1

    2
    2
    2
    3
    
  • 输入#2

    4
    1
    1
    2
    3
    

    输出#2

    2
    2
    2
    2
    
首页