#P1983. [NOIP 2013 普及组] 车站分级

    ID: 929 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>图论贪心2013NOIp 普及组O2优化排序图的建立,建图拓扑排序

[NOIP 2013 普及组] 车站分级

Description

Along a one-way railway line, there are nn stations numbered 1,2,,n1, 2, \dots, n in order. Each station has a level, with the minimum level being 11. There are several train services operating on this line, and each service satisfies the following rule: if the service stops at station xx, then among the stations between its origin and terminal station, every station whose level is greater than or equal to the level of station xx 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 55 services. Among them, the first 44 services satisfy the rule, while the 55-th service does not, because it stops at station 33 (level 22) but skips station 66 (also level 22) along the route.

Given the operation of mm services (all of which satisfy the rule), determine the minimum number of distinct levels needed for these nn stations.

Input Format

The first line contains 22 positive integers n,mn, m, separated by a space.

On line i+1i + 1 for 1im1 \le i \le m, first there is a positive integer sis_i (2sin2 \le s_i \le n), indicating that the ii-th service has sis_i stops; then follow sis_i 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 nn 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 20%20\% of the testdata, 1n,m101 \le n, m \le 10.

For 50%50\% of the testdata, 1n,m1001 \le n, m \le 100.

For 100%100\% of the testdata, 1n,m10001 \le n, m \le 1000.

Translated by ChatGPT 5