#d2154. 树
树
Tree
Problem Description
There is a rooted tree with nodes, rooted at node . 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 (), you want to know the minimum number of operations required so that the graph has exactly connected components.
Input Format
The first line contains a positive integer .
The second line contains integers , where is the father of node . It is guaranteed that .
Output Format
Output integers. The -th integer is the answer when ; if it is impossible to make the graph have exactly connected components, output -1.
Sample Input
6
1 2 1 1 2
Sample Output
0 -1 1 1 -1 2
Constraints
There are test cases in total.
Test cases satisfy .
Test cases satisfy .
For all data, .
Hint
See the distributed files.