Codeforces Round #253 (Div. 1)D题
来源:互联网 发布:淘宝刀创 编辑:程序博客网 时间:2024/05/23 14:38
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 ≤ 106) — the number of times a new vertex is added. The second line contains n numbers pi (1 ≤ pi ≤ 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.
111 1 1 3 4 4 7 3 7 6 6
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.
- Codeforces Round #253 (Div. 1)D题
- Codeforces Round #250 (Div. 2) && (Div. 1) D题
- Codeforces Round #238 (Div. 1) D题(倍增lca)
- Codeforces Round #310 (Div. 1) A B C D题
- Codeforces Round #261 (Div. 2) D题
- Codeforces Round #277 (Div. 2)D题
- Codeforces Round #202 (Div. 1) D. Turtles
- Codeforces Round #225 (Div. 1) D. Antimatter
- Codeforces Round #276 (Div. 1) D. Kindergarten
- Codeforces Round #286 (Div. 1) C、D
- Codeforces Round #434 Div.1 D graph
- Codeforces Round #400 (Div. 1 + Div. 2, combined)D
- Codeforces Round #400 (Div. 1 + Div. 2, combined)D
- Codeforces 615D Multipliers (Round #338 (Div. 2) D题)
- Codeforces 617D Polyline (Round #340 (Div. 2) D题)
- Codeforces Round #237 (Div. 2) D. Minesweeper 1D
- Codeforces Round #237 (Div. 2) D Minesweeper 1D
- Codeforces Round #237 (Div. 2)-D. Minesweeper 1D
- 【数据结构_map容器迭代】Anagrams
- mahou 安装实例
- SRM556题解(T3除外)
- Linux驱动的platform机制
- Poj2653
- Codeforces Round #253 (Div. 1)D题
- 2014 MySql安装图解
- 黑马程序员—java技术blog—第四篇:List和Set的总结
- UILabel设置多种字体、颜色
- 嵌入式软件开发工程师成长历程
- Poj1113
- oracle11g导9i后的问题
- HDU 4902Nice boat
- linux下svn常用指令