QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 128 MB Total points: 10

#10671. Byton Tree [B]

统计

Bytons grow on a byton tree. They are rare fruits and they can only be found on branches from which no other branches grow.

All bytons growing on a single branch have the same time interval in which they can be picked. If they are picked too early, they will be unripe, and if too late, they will be rotten. Every person owning a byton tree wonders how many cuts need to be performed for all bytons to be collected and for each collected byton to be eatable in the moment it is picked. Cuts can be performed at each branch, near its beginning. When a cut is performed, all bytons growing directly or indirectly on the corresponding branch are picked. We assume that an arbitrary number of cuts can be performed in one unit of time and that the trunk is also a branch.

Input Format

The first and only line of the standard input contains a description of a byton tree, written in a recursive manner. The first integer denotes the number of branches growing on the trunk; it is followed by the descriptions of these branches. A description of a branch consists of the number of branches that grow on it, followed by descriptions of these branches. If any bytons grow on a branch, 0 is written as the number of branches growing on it and it is followed by two integers $a_{i}$, $b_{i}$ ($1 ≤ a_{i} ≤ b_{i} ≤ 10^{9}$) which denote the time interval when the bytons can be collected. The total number of all branches does not exceed $1\,000\,000$.

Output Format

The first and only line of the standard output should contain a single integer denoting the minimal number of cuts that need to be performed for all the picked bytons to be eatable.

Example

Input

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

Output

2
problem_10671_1.gif

Explanation of the example: The byton tree from the example contains 3 branches on which bytons grow - the intervals in the figure represent their periods of eatability. In order to collect all bytons, 2 cuts are sufficient: the first one can be performed e.g. in moment 5, the second one in moment 8.

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.