#P11885. Island Hopping with Limited Jumps

    ID: 13988 Type: Default 1000ms 256MiB

Island Hopping with Limited Jumps

Island Hopping with Limited Jumps

You are given nn islands numbered from 11 to nn. In addition, you are given a sequence of positive integers v1,v2,,vn1v_1, v_2, \ldots, v_{n-1} of length n1n-1. When you are on island ii (with 1i<n1 \le i < n), you can jump either to island i+1i+1 or to island viv_i (note that i<vii < v_i).

You are also given a positive integer kk. For each island ii, define $$f(i,k)$$ as the number of distinct islands that can be reached from island ii by performing at most kk jumps (including the starting island itself).

It is guaranteed that the sequence viv_i satisfies the following special property: for any 1i<j<n1 \le i < j < n, either $$v_i \le j$$ or $$v_j \le v_i$$.

For each island i=1,2,,ni=1,2,\ldots,n, compute $$f(i,k)$$.

Note: Even if there are multiple ways to reach an island within kk jumps, that island is only counted once. Also, observe that since the jumps are only in the forward direction, the set of reachable islands will always form a contiguous segment of islands.

inputFormat

The first line contains two positive integers nn and kk, where nn is the number of islands and kk is the maximum number of jumps allowed.

The second line contains n1n-1 positive integers: v1,v2,,vn1v_1,v_2,\ldots,v_{n-1}.

outputFormat

Output nn integers. The ii-th integer should be equal to $$f(i,k)$$, the number of distinct islands that can be reached from island ii using at most kk jumps. The answers should be printed in order from island 11 to island nn, separated by spaces.

sample

5 2
3 3 5 5
5 4 3 2 1