QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 128 MB Points totaux : 10

#10671. Byton Tree [B]

Statistiques

Bytons 生长在 Byton 树上。它们是稀有的果实,只能在没有其他分支生长的分支上找到。

生长在同一分支上的所有 Bytons 都有相同的可采摘时间区间。如果采摘过早,它们会未成熟;如果采摘过晚,它们会腐烂。每一位拥有 Byton 树的人都想知道,为了收集所有的 Bytons,并且使每个被收集的 Byton 在采摘时都是可食用的,需要进行多少次切割。切割可以在每个分支的起始处进行。当进行一次切割时,所有直接或间接生长在该分支上的 Bytons 都会被采摘。我们假设在单位时间内可以进行任意次数的切割,并且树干也被视为一个分支。

输入格式

标准输入的第一行也是唯一一行包含以递归方式描述的 Byton 树。第一个整数表示生长在树干上的分支数量;随后是这些分支的描述。一个分支的描述由生长在其上的分支数量组成,随后是这些分支的描述。如果某个分支上生长有 Bytons,则该分支上生长的分支数量记为 0,随后是两个整数 $a_{i}, b_{i}$ ($1 \le a_{i} \le b_{i} \le 10^{9}$),表示 Bytons 可以被收集的时间区间。所有分支的总数不超过 $1\,000\,000$。

输出格式

标准输出的第一行也是唯一一行应包含一个整数,表示为了使所有被采摘的 Bytons 均可食用,所需进行的最少切割次数。

样例

输入 1

2 1 0 3 5 2 0 8 10 1 0 6 9

输出 1

2

说明 1

样例中的 Byton 树包含 3 个生长有 Bytons 的分支——图中的区间表示它们的可食用周期。为了收集所有的 Bytons,2 次切割就足够了:第一次切割可以在例如时刻 5 进行,第二次切割可以在时刻 8 进行。

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.