PivotOJ

Protecting Kingdom

시간 제한: 1000ms메모리 제한: 2048MB출처: ICPC Asia Seoul Regional 2024BOJ 32836

문제

In the kingdom of CPIC (Committee for Public Infrastructure Conservation), there are nn villages numbered from 11 to nn and connected by a network of n1n - 1 roads forming a tree structure. Each road connects two villages and has a positive length. Specifically, the ii-th road connects village i+1i + 1 with village pip_i (1 ≤ p_i ≤ i) and has a length of lil_i. Due to treacherous terrains and past incidents, some points along these roads are identified as hazardous.

On the ii-th road, there are kik_i hazardous points located at specific distances xi,1,xi,2,,xi,kix_{i,1}, x_{i,2}, \dots , x_{i, k_i} from village pip_i, satisfying 0<xi,1<xi,2<<xi,ki<li0 < x_{i, 1} < x_{i, 2} < \cdots < x_{i, k_i} < l_i. These distances are integers, indicating positions along the road.

The newly established CPIC Safety Committee aims to enhance traveler safety by deploying a protective measure. They can select any two points on the roads, including villages, and secure the shortest path between them. The path can cover all hazardous points located exactly on it, including its endpoints, and its length must not exceed a given length ww.

Given the road network, the positions of the hazardous points, and the maximum allowable path length ww, write a program to determine the maximum number of hazardous points that can be covered by optimally choosing the two points and securing the shortest path between them with length &le; w.

입력

Your program is to read from standard input. The input starts with a line containing two integers, nn and ww (2 &le; n &le; 250\,000, 1 &le; w &le; 10^{18}), where nn is the number of villages and ww is the maximum allowable length of the secured path. In the following n1n - 1 lines, the ii-th line, which provides information about the ii-th road, starts with three integers pip_i, lil_i, and kik_i (1 &le; p_i &le; i, 1 &le; l_i &le; 10^{12}, k_i &ge; 0), where pip_i is the village connected to village i+1i + 1 by the road, lil_i is the length of the road, and kik_i is the number of hazardous points on the road. If ki>0k_i > 0, the line is followed by kik_i integers xi,1,xi,2,,xi,kix_{i,1}, x_{i,2}, \dots , x_{i, k_i} (0<xi,1<xi,2<<xi,ki<li0 < x_{i, 1} < x_{i, 2} < \cdots < x_{i, k_i} < l_i), representing the distances from village pip_i to each hazardous point along the road. The total number of hazardous points k1+k2++kn1k_1 + k_2 + \cdots + k_{n-1} does not exceed 10610^6.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the maximum number of hazardous points that can be covered by a shortest path of length ww or less between any two points on the roads.

예제

예제 1

입력
4 2
1 2 1 1
1 610 2 1 100
3 2001 0
출력
2

예제 2

입력
2 2
1 2 1 1
출력
1

예제 3

입력
8 6
1 2 1 1
1 3 2 1 2
2 1 0
3 4 1 2
2 3 1 1
1 4 1 3
3 4 1 1
출력
4
코드를 제출하려면 로그인하세요.