Describe
A one-way railway line, numbered 1, 2, ..., N of n stations. Each station has a level, at least 1 levels. There are several trips on this line, each meeting the following requirements: If this train stops at Station X, then all levels greater than or equal to station x must be docked between the departure and terminal.
(Note: The starting station and terminal are naturally counted as pre-known sites that need to be docked)
For example, the following table is the operation of 5 trips. Among them, the first 4 trips to meet the requirements, and the 5th trip due to stop at train station 3rd (level 2) but did not stop at the 6th train station (also 2 level) and do not meet the requirements.
The operation of the existing M-Train (all meet the requirements), try to calculate that the N train station at least a few different levels.
Format input Format
The first line contains 2 positive integers n, m, separated by a space.
In line i + 1 (1≤i≤m), the first is a positive integer s I (2≤s i≤n), which indicates that the I train has S I station; next there is a positive integer of S I, which indicates the numbering of all the stops, arranged from small to large. Each of the two numbers is separated by a space. Enter to ensure that all trains meet the requirements.
Output format
The output has only one row and contains a positive integer, which is the minimum number of levels divided by the N train station.
Example 1 sample input 1[copy]
9 24 1 3 5 63 3 5 6
Sample output 1[Copy]
2
Example 2 sample input 2[copy]
9 34 1 3 5 63 3 5 63 1 5 9
Sample output 2[Copy]
3
Limit
Each test point is 1s.
Tips
For 20% of data, 1≤n, m≤10;
For 50% of data, 1≤n, m≤100;
For 100% of data, 1≤n, m≤1000
Simple topological sort, I actually watched the day ...
1#include <iostream>2#include <cstring>3 using namespacestd;4 5 Const intmaxn= ++Ten;6 intn,m,ans=0;7 intb[maxn]={0},r[maxn]={0},sk[maxn]={0};8 BOOLa[maxn]={0},f[maxn]={0},e[maxn][maxn]={0};9 Ten intMain () One { ACin>>n>>m; - for(intI=1; i<=m;i++) - { the ints; -memset (A,0,sizeof(A)); -Cin>>s; - for(intj=1; j<=s;j++) + { -Cin>>B[j]; +a[b[j]]=1; A } at for(inti=a[1];j<=b[s];j++) - if(!A[j]) - for(intk=1; k<=s;k++) - if(!E[j][b[k]]) - { -e[j][b[k]]=1; inr[b[k]]++; - } to } + inttop; - while(1) the { *top=0; $ for(intI=1; i<=n;i++)Panax Notoginseng if(! r[i]&&!F[i]) - { thesk[++top]=i; +f[i]=1; A } the if(top==0) Break; + for(intI=1; i<=top;i++) - for(intj=1; j<=n;j++) $ if(E[sk[i]][j]) $ { -e[sk[i]][j]=0; -r[j]--; the } -ans++;Wuyi } thecout<<ans<<Endl; - return 0; Wu}
NOIP2013 Station Grading