#P3066. [USACO12DEC] Running Away From the Barn G
[USACO12DEC] Running Away From the Barn G
Description
Given a rooted tree with nodes and weighted edges. Nodes are numbered from to , and node is the root.
Given a parameter , for each node , find how many nodes in the subtree of have distance to not greater than .
Input Format
The first line contains two integers, the number of nodes and the parameter .
For each from to , the -th line contains two integers , meaning the parent of node is , and the weight of the edge connecting and is .
Output Format
Output lines. The -th line contains an integer, the number of nodes in the subtree of whose distance to is at most .
4 5
1 4
2 3
1 5
3
2
1
1
Hint
Constraints
- , .
- , .
Translated by ChatGPT 5
京公网安备 11011102002149号