Time limit: 1 second Memory limit: 256 MB Day 2 of period 31 Daoud and Mashtali went to…
Rate quality
Private research annotation
Sign in to add a private research label or note.
- User
Time limit: 1 second Memory limit: 256 MB Day 2 of period 31 Daoud and Mashtali went to the beaches of Hawaii for a vacation, and during an operation, Mashtali owed Daoud several hectares of land in Hawaii. The map of Hawaii's coast is in the shape of a tree, but scientists have not yet obtained detailed information about its shape. Now Mashtli wants to escape from Dawood. Since this money is not counted as a number for Dawood, he only demands the money from Mushtli if his distance from Mushtli is less than d be d. A handful of those who have the gold of the Accounting Olympiad turn to accounting. Mashtli equals the value of a tree to the number of vertices of the tree, for example v v defines that if David at the head v be v, Mushtli can be placed in a vertex whose distance from Dawood is greater than or equal to d be d.
Shayan is one of the famous geologists of the century 21 is 21 and is researching the beaches of Hawaii. He is a tree n n with a vertex and a root whose root is a vertex as usual 1 He gives 1 to Mushtli and says that the map of the coast of Hawaii is one of the subtrees of this tree. Now Mushtli, Shayan tree and number d It gives you input d and in return it wants for each vertex e.g v v, subtree value v Obtain v.
In a rooted tree, the root subtree v v includes all vertices like u u is the shortest path between the root and u u vertex v v has appeared.
input In the first line, two numbers n n and d d has come.
In the next line n
1 n−1 is the number in position i I am the father of Ross i + 1 My i+1 has arrived.
2 ≤ n ≤ 3 x 1 0 5 2≤n≤3×10 5
1 ≤ d ≤ n 1≤d≤n
output in one line n n number print that number i i th value of the vertex subtree i i is
Sub-issues Constraint score subproblem 1 7 n ≤ 300 n≤300 2 12 n ≤ 3000 n≤3000 3 17 The maximum height of the tree is 40 4 43 n ≤ 1 0 5 n≤10 5
5 21 without additional restrictions Example Sample entry 1 3 2 1 2 Plain text Sample output 1 2 0 0 Plain text Sample entry 2 11 4 1 1 2 2 3 4 5 8 8 10 Plain text Sample output 2 11 7 0 0 0 0 0 0 0 0 0 Plain text Sample entry 3 11 3 1 1 2 2 3 4 5 8 8 10 Plain text Sample output 3 11 8 0 0 3 0 0 2 0 0 0 write in c++
- Assistant