Protecting Kingdom

시간 제한1초메모리 제한2048 MB

요약
가중치가 있는 트리의 간선 위에 표시된 점들이 있을 때, 길이가 w 이하인 두 점 사이 경로로 덮을 수 있는 표시점의 최대 개수를 구한다.
난이도

어려움10점 중 9점

유형
트리, DFS, 그리디, 투 포인터
정답자
아직 제출이 없습니다

문제

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 n−1n - 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 p_ip\_i (1≤p_i≤i1 ≤ p\_i ≤ i) and has a length of l_il\_i. Due to treacherous terrains and past incidents, some points along these roads are identified as hazardous.

On the ii-th road, there are k_ik\_i hazardous points located at specific distances x_i,1,x_i,2,…,x_i,k_ix\_{i,1}, x\_{i,2}, \dots , x\_{i, k\_i} from village p_ip\_i, satisfying 0<x_i,1<x_i,2<⋯<x_i,k_i<l_i0 < 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 ≤w≤ w.

입력

Your program is to read from standard input. The input starts with a line containing two integers, nn and ww (2≤n≤250,0002 ≤ n ≤ 250\\,000, 1≤w≤10181 ≤ w ≤ 10^{18}), where nn is the number of villages and ww is the maximum allowable length of the secured path. In the following n−1n - 1 lines, the ii-th line, which provides information about the ii-th road, starts with three integers p_ip\_i, l_il\_i, and k_ik\_i (1≤p_i≤i1 ≤ p\_i ≤ i, 1≤l_i≤10121 ≤ l\_i ≤ 10^{12}, k_i≥0k\_i ≥ 0), where p_ip\_i is the village connected to village i+1i + 1 by the road, l_il\_i is the length of the road, and k_ik\_i is the number of hazardous points on the road. If k_i>0k\_i > 0, the line is followed by k_ik\_i integers x_i,1,x_i,2,…,x_i,k_ix\_{i,1}, x\_{i,2}, \dots , x\_{i, k\_i} (0<x_i,1<x_i,2<⋯<x_i,k_i<l_i0 < x\_{i, 1} < x\_{i, 2} < \cdots < x\_{i, k\_i} < l\_i), representing the distances from village p_ip\_i to each hazardous point along the road. The total number of hazardous points k_1+k_2+⋯+k_n−1k\_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.

예제3

  1. 예제 1

    입력
    4 2
    1 2 1 1
    1 610 2 1 100
    3 2001 0
    
    예상 출력
    2
    
  2. 예제 2

    입력
    2 2
    1 2 1 1
    
    예상 출력
    1
    
  3. 예제 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