"Here in
ParkourJump Civilization, No One Chooses to Jump for the Beef" ━ Evbo - Parkour Civilization, the movie
Task
In jump civilization, the world consists of floating islands, numbered to . When at island (for ), the members of jump civilization can either take:
- an easy jump, from island to island ; or
- a difficult jump, from island to island , where .
In order to rank up in jump civilization, the members of jump civilization need to compute the jumping power of each island. The jumping power of island is the number of islands which can be reached by starting at island and using at most jumps.
The previous Jump Champion, wanting to make sure that the jumping course is fair, instituted the following important rule: Whenever , either or .
You, as an aspiring member of jump civilization, want to find the jumping power of every island - can you do this efficiently?
Input data
The first line of the input contains two space-separated integers , . The second line of the input contains space-separated integers .
Output data
Output space-separated integers, the jumping power of the islands in order.
Constraints and clarifications
- For , either or .
- If island can be reached from island in two different ways using at most jumps, then the island is only counted once for the jumping power of island .
- When computing the jumping power of an island, it doesn't matter whether we use easy or difficult jumps — only the number of jumps matters.
# | Points | Restrictions |
---|---|---|
1 | 6 | |
2 | 27 | and |
3 | 11 | for |
4 | 37 | |
5 | 19 | No additional constraints |
Example 1
stdin
5 1
4 3 4 5
stdout
3 2 2 2 1
Explanations
From island , one can reach island without jumping, and islands and with jump. In total, the jumping power of island is .
Example 2
stdin
6 2
2 3 5 5 6
stdout
3 4 4 3 2 1