#d2154. 树

树

Tree

Problem Description

There is a rooted tree with nn nodes, rooted at node 11. You may perform several operations on this tree; in each operation you may choose a node and delete all edges connecting this node to its sons.

For every kk (1≤k≤n1 \le k \le n), you want to know the minimum number of operations required so that the graph has exactly kk connected components.

Input Format

The first line contains a positive integer nn.

The second line contains n−1n-1 integers f1,f2,…,fn−1f_1, f_2, \dots, f_{n-1}, where fif_i is the father of node i+1i+1. It is guaranteed that 1≤fi≤i1 \le f_i \le i.

Output Format

Output nn integers. The ii-th integer is the answer when k=ik = i; if it is impossible to make the graph have exactly ii connected components, output -1.

Sample Input

6
1 2 1 1 2

Sample Output

0 -1 1 1 -1 2

Constraints

There are 1010 test cases in total.

Test cases 1,2,31, 2, 3 satisfy n≤20n \le 20.

Test cases 4,5,64, 5, 6 satisfy n≤100n \le 100.

For all data, 1≤n≤30001 \le n \le 3000.

Hint

See the distributed files.