#P1983. [NOIP 2013 普及组] 车站分级
[NOIP 2013 普及组] 车站分级
Description
Along a one-way railway line, there are stations numbered in order. Each station has a level, with the minimum level being . There are several train services operating on this line, and each service satisfies the following rule: if the service stops at station , then among the stations between its origin and terminal station, every station whose level is greater than or equal to the level of station must also be a stop.
Note: The origin and terminal stations are, of course, also counted as known stops.
For example, the table below shows the operation of services. Among them, the first services satisfy the rule, while the -th service does not, because it stops at station (level ) but skips station (also level ) along the route.

Given the operation of services (all of which satisfy the rule), determine the minimum number of distinct levels needed for these stations.
Input Format
The first line contains positive integers , separated by a space.
On line for , first there is a positive integer (), indicating that the -th service has stops; then follow positive integers, the indices of all stops, in increasing order. Each pair of numbers is separated by a single space. The input guarantees that all services satisfy the rule.
Output Format
Output a single integer, the minimum number of levels into which the stations can be partitioned.
9 2
4 1 3 5 6
3 3 5 6
2
9 3
4 1 3 5 6
3 3 5 6
3 1 5 9
3
Hint
For of the testdata, .
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号