QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#10542. Protecting Kingdom

統計

在 CPIC(公共基础设施保护委员会)王国中,有 $n$ 个村庄,编号从 1 到 $n$,由 $n - 1$ 条道路连接,形成树状结构。每条道路连接两个村庄,且具有正长度。具体而言,第 $i$ 条道路连接村庄 $i + 1$ 和村庄 $p_i$ ($1 \le p_i \le i$),长度为 $l_i$。由于地形险峻及过往事故,这些道路上的某些点被标记为危险点。

在第 $i$ 条道路上,有 $k_i$ 个危险点,它们距离村庄 $p_i$ 的距离分别为 $x_{i,1}, x_{i,2}, \dots, x_{i,k_i}$,满足 $0 < x_{i,1} < x_{i,2} < \dots < x_{i,k_i} < l_i$。这些距离均为整数,表示道路上的位置。

新成立的 CPIC 安全委员会旨在通过部署保护措施来提高旅行者的安全。他们可以选择道路上的任意两个点(包括村庄),并保护这两点之间的最短路径。该路径可以覆盖位于其上的所有危险点(包括路径端点),且路径长度不得超过给定的长度 $w$。

给定道路网络、危险点的位置以及最大允许路径长度 $w$,请编写一个程序,通过最优地选择两个点并保护它们之间长度 $\le w$ 的最短路径,确定所能覆盖的危险点的最大数量。

输入格式

程序从标准输入读取数据。输入的第一行包含两个整数 $n$ 和 $w$ ($2 \le n \le 250,000$, $1 \le w \le 10^{18}$),其中 $n$ 是村庄数量,$w$ 是受保护路径的最大允许长度。接下来的 $n - 1$ 行中,第 $i$ 行提供了关于第 $i$ 条道路的信息,以三个整数 $p_i, l_i, k_i$ ($1 \le p_i \le i$, $1 \le l_i \le 10^{18}$, $k_i \ge 0$) 开头,其中 $p_i$ 是与村庄 $i + 1$ 相连的村庄,$l_i$ 是道路长度,$k_i$ 是该道路上的危险点数量。如果 $k_i > 0$,该行后面会跟随 $k_i$ 个整数 $x_{i,1}, x_{i,2}, \dots, x_{i,k_i}$ ($0 < x_{i,1} < x_{i,2} < \dots < x_{i,k_i} < l_i$),表示从村庄 $p_i$ 到沿途每个危险点的距离。危险点总数 $k_1 + k_2 + \dots + k_{n-1}$ 不超过 $10^6$。

输出格式

程序输出到标准输出。仅打印一行,包含通过长度不超过 $w$ 的最短路径所能覆盖的危险点的最大数量。

样例

输入 1

4 2
1 2 1 1
1 610 2 1 100
3 2001 0

输出 1

2

输入 2

2 2
1 2 1 1

输出 2

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

输出 3

4

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#610Editorial Open集训队作业 解题报告 by 彭亦宸Qingyu2026-01-02 23:07:42 Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.