codeforces 842E. Nikita and game
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 842E. Nikita and game相关的知识,希望对你有一定的参考价值。
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 yi (and yi 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.
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 yi — the index of the parent-class of class with index i + 1 (1 ≤ yi ≤ 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.
维护重心和点到重心的距离来处理直径
以上是关于codeforces 842E. Nikita and game的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #393 (Div. 2) E题Nikita and stack(线段树)解题报告
Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition) E - Nikita and st
Codeforces Round #442 (Div. 2) B. Nikita and string
CodeForces - 993E Nikita and Order Statistics