CF379F.New Year Tree

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are a programmer and you have a New Year Tree (not the traditional fur tree, though) — a tree of four vertices: one vertex of degree three (has number 1), connected with three leaves (their numbers are from 2 to 4).

On the New Year, programmers usually have fun. You decided to have fun as well by adding vertices to the tree. One adding operation looks as follows:

  • First we choose some leaf of the tree with number vv .
  • Let's mark the number of vertices on the tree at this moment by variable nn , then two vertexes are added to the tree, their numbers are n+1n+1 and n+2n+2 , also you get new edges, one between vertices vv and n+1n+1 and one between vertices vv and n+2n+2 .

Your task is not just to model the process of adding vertices to the tree, but after each adding operation print the diameter of the current tree. Come on, let's solve the New Year problem!

输入格式

The first line contains integer qq (1<=q<=5105)(1<=q<=5·10^{5}) — the number of operations. Each of the next qq lines contains integer viv_{i} (1<=vi<=n)(1<=v_{i}<=n) — the operation of adding leaves to vertex viv_{i} . Variable nn represents the number of vertices in the current tree.

It is guaranteed that all given operations are correct.

输出格式

Print qq integers — the diameter of the current tree after each operation.

输入输出样例

  • 输入#1

    5
    2
    3
    4
    8
    5
    

    输出#1

    3
    4
    4
    5
    6
    
首页