#P3066. [USACO12DEC] Running Away From the Barn G

[USACO12DEC] Running Away From the Barn G

Description

Given a rooted tree with nn nodes and weighted edges. Nodes are numbered from 11 to nn, and node 11 is the root.

Given a parameter tt, for each node uu, find how many nodes in the subtree of uu have distance to uu not greater than tt.

Input Format

The first line contains two integers, the number of nodes nn and the parameter tt.

For each ii from 22 to nn, the ii-th line contains two integers pi,wip_i, w_i, meaning the parent of node ii is pip_i, and the weight of the edge connecting ii and pip_i is wiw_i.

Output Format

Output nn lines. The ii-th line contains an integer, the number of nodes in the subtree of ii whose distance to ii is at most tt.

4 5 
1 4 
2 3 
1 5 

3 
2 
1 
1 

Hint

Constraints

  • 1n2×1051 \leq n \leq 2 \times 10^5, 1t10181 \leq t \leq 10^{18}.
  • 1pi<i1 \leq p_i \lt i, 1wi10121 \leq w_i \leq 10^{12}.

Translated by ChatGPT 5