시간 제한메모리 제한제출정답맞힌 사람정답 비율
10 초 64 MB0000.000%

문제

A tree is one of the most popular data structures in computer science. Tree itself is very elegant, but it is incompatible with current computer architecture. In the current architecture, memory can be regarded as a one-dimensional array. Since a tree is not a one-dimensional structure, cache efficiency may come into question when we allocate a tree on memory. We can access the data faster if it is contained in cache. Let us consider the allocation of nodes of a tree which achieves high cache performance.

We define the cost of allocation for a tree as follows. For simplicity, we regard memory to be separated to blocks each can store at most B nodes of a tree. When we access data in a block, all data in the block are stored in cache and access request to data in the block will be faster. The cost of an access to node u after node v is 0 if u and v are in same block, and 1 otherwise. Initially, cache has no data and the cost of an access to a node is always 1. The cost of the path v1, v2,..., vn is sum of the cost when we access the nodes v1, v2,..., vn in this order. For a tree, we define the cost of allocation as a maximum cost of the paths from root node to each terminal node.

The figures below show examples of allocation when B = 4 and node 1 is the root node (it corresponds to the tree described in the third sample input). Each frame represents a block. The left figure is an example of allocation whose cost is 3. It is not optimal, because the right example achieves the optimal allocation cost 2.

Given a tree, for each node i in the tree, calculate the minimum cost of allocation when the node i is the root node.

입력

The input contains several test cases. Each test case starts with a line containing two integers N (1 ≤ N ≤ 100,000) and B (1 ≤ B ≤ N), separated by a single space. Each of the next N − 1 lines contains an integer. The i-th integer pi (1 ≤ pi ≤ i) denotes that the node i + 1 and the node pi are connected. The nodes are numbered from 1 to N.

The last test case is followed by a line containing two zeros.

출력

For each test case, print its case number. Then print N lines. The i-th line should contain an integer which denotes the minimum cost of allocation of the given tree when node i is the root node.

Follow the format of the sample output.

예제 입력 1

3 1
1
2
3 2
1
1
10 4
1
1
2
3
3
4
4
4
5
0 0

예제 출력 1

Case 1:
3
2
3
Case 2:
2
2
2
Case 3:
2
2
2
2
2
2
2
2
2
3