302298: CF442D. Adam and Tree

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Adam and Tree

题意翻译

树指的是一种无向连通图且满足任意两个点间不存在两条不同的简单路径; 彩色树指的是一种每条边都有一种颜色的树,并且同一种颜色的边集一定形成一条路径。 对于彩色树上的任意一个点u,定义其权值w(u)为u至根节点(即1号点)的路径上所有边的颜色种类数。 彩色树会生长,初始时树中仅有根节点1号点,每个时刻都会有一个新节点长出来。每个时刻 (包括初始时刻),你需要决定每条边的颜色,在满足彩色树的定义的前提下,使这个时刻树中节点权 值的最大值最小。 输入格式 第1行1个正整数n。 接下来n-1行,第i行1个正整数fi,表示第i时刻加入点i且其父亲为fi 输出格式 共n行,第i行一个整数表示时刻i的答案。

题目描述

When Adam gets a rooted tree (connected non-directed graph without cycles), he immediately starts coloring it. More formally, he assigns a color to each edge of the tree so that it meets the following two conditions: - There is no vertex that has more than two incident edges painted the same color. - For any two vertexes that have incident edges painted the same color (say, $ c $ ), the path between them consists of the edges of the color $ c $ . Not all tree paintings are equally good for Adam. Let's consider the path from some vertex to the root. Let's call the number of distinct colors on this path the cost of the vertex. The cost of the tree's coloring will be the maximum cost among all the vertexes. Help Adam determine the minimum possible cost of painting the tree. Initially, Adam's tree consists of a single vertex that has number one and is the root. In one move Adam adds a new vertex to the already existing one, the new vertex gets the number equal to the minimum positive available integer. After each operation you need to calculate the minimum cost of coloring the resulting tree.

输入输出格式

输入格式


The first line contains integer $ n $ ( $ 1<=n<=10^{6} $ ) — the number of times a new vertex is added. The second line contains $ n $ numbers $ p_{i} $ ( $ 1<=p_{i}<=i $ ) — the numbers of the vertexes to which we add another vertex.

输出格式


Print $ n $ integers — the minimum costs of the tree painting after each addition.

输入输出样例

输入样例 #1

11
1 1 1 3 4 4 7 3 7 6 6

输出样例 #1

1 1 1 1 1 2 2 2 2 2 3 

说明

The figure below shows one of the possible variants to paint a tree from the sample at the last moment. The cost of the vertexes with numbers 11 and 12 equals 3. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF442D/6877a658192cab08c1f166dfd261ee256f3df3a2.png)

Input

题意翻译

树指的是一种无向连通图且满足任意两个点间不存在两条不同的简单路径; 彩色树指的是一种每条边都有一种颜色的树,并且同一种颜色的边集一定形成一条路径。 对于彩色树上的任意一个点u,定义其权值w(u)为u至根节点(即1号点)的路径上所有边的颜色种类数。 彩色树会生长,初始时树中仅有根节点1号点,每个时刻都会有一个新节点长出来。每个时刻 (包括初始时刻),你需要决定每条边的颜色,在满足彩色树的定义的前提下,使这个时刻树中节点权 值的最大值最小。 输入格式 第1行1个正整数n。 接下来n-1行,第i行1个正整数fi,表示第i时刻加入点i且其父亲为fi 输出格式 共n行,第i行一个整数表示时刻i的答案。

加入题单

算法标签: