Running Away From the Barn

No attempts yetTime limit1sMemory limit128 MB

Problem

It is milking time on the farm, but all the cows have run away! To round them up you first need to work out how far each cow could possibly have gone.

The farm has $N$ pastures ($1 \le N \le 200{,}000$) numbered $1 \dots N$, connected by $N - 1$ bidirectional paths. The barn is at pasture $1$, and every pasture is reachable from the barn, so the pastures form a tree rooted at the barn.

Every cow starts the morning in its own pasture. A cow only runs away from the barn (it never moves back toward it), and it is too lazy to travel a total distance greater than $L$. For every pasture, determine how many distinct pastures a cow starting there could end up in (including its starting pasture).

Because the distances can be large, store them in 64-bit integers.

Input

  • Line $1$: two integers $N$ and $L$ ($1 \le N \le 200{,}000$, $1 \le L \le 10^{18}$).
  • Lines $2 \dots N$: line $i$ contains two integers $p_i$ and $l_i$. Here $p_i$ ($1 \le p_i < i$) is the next pasture on the shortest path from pasture $i$ toward the barn (that is, the parent of pasture $i$), and $l_i$ ($1 \le l_i \le 10^{12}$) is the length of the path joining pasture $i$ and pasture $p_i$.

Output

  • Lines $1 \dots N$: print one integer per line. The number on line $i$ is how many pastures can be reached from pasture $i$ by following paths that lead strictly farther away from the barn (pasture $1$), such that the total distance travelled does not exceed $L$.

Hint

In the example, cows from pasture $1$ can hide in pastures $1$, $2$, and $4$. Cows from pasture $2$ can hide in pastures $2$ and $3$. Pastures $3$ and $4$ are the farthest from the barn, so a cow there can only stay put.