PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000049. Chạy khỏi chuồng bò (Running Away From the Barn)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Chạy khỏi chuồng bò (Running Away From the Barn)

Running Away From the Barn

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

A farm consists of nn pastures connected as a weighted tree rooted at the barn, pasture 11. From its starting pasture, a cow may only take roads that lead strictly farther from the barn, i.e. down the rooted tree.

The total traveled distance cannot exceed LL, and the cow may also stay where it started. For each starting pasture vv, count how many different pastures can be reached under these rules.

Input

  • The first line contains n,Ln,L.
  • For each i=2,…,ni=2,\ldots,n, line ii contains pi,wip_i,w_i. Here pi<ip_i<i is pasture ii's parent and wiw_i is the length of edge (pi,i)(p_i,i).

Output

Print exactly nn lines. Line vv gives the number of possible final pastures from vv, including vv itself.

Subtasks

General constraints: 1≤n≤2⋅1051\le n\le2\cdot10^5; 1≤L≤10181\le L\le10^{18}; 1≤pi<i1\le p_i<i; 1≤wi≤10121\le w_i\le10^{12}.

  • Subtask 1 (20 points): 1≤n≤401\le n\le 40.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000.

  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000.

Examples

Input

4 5
1 4
2 3
1 5

Output

3
2
1
1

Explanation

From pasture 11, a cow can reach 1,2,41,2,4 with travel lengths 0,4,50,4,5. It cannot reach 33 because the route 1−2−31-2-3 has length 7>57>5. From pasture 22, it can reach 22 or 33; pastures 33 and 44 can only reach themselves.