kingofpupil @ 2019-02-27 21:21:54
#include<bits/stdc++.h>
using namespace std;
int ans,dep[1003],yes[1003],edge[1003][1003],rd[1003],fir[1003],nxt[1003],to[1003],n,m,k,s[1003],tot;
inline void add(int x,int y){
edge[x][y]=true;
to[++tot]=y; nxt[tot]=fir[x]; fir[x]=tot; rd[y]=1;
}
inline void dfs(int x,int cnt){
if (dep[x]>=cnt) return;
dep[x]=cnt;
for (int i=fir[x];i;i=nxt[i])
dfs(to[i],cnt+1);
}
int main(){
scanf("%d%d",&n,&m);
while (m--){
scanf("%d",&k);
for (int i=1;i<=k;i++){
scanf("%d",&s[i]);
yes[s[i]]=1;
}
for (int i=s[1]+1;i<s[k];i++)
if (!yes[i])
for (int j=1;j<=k;j++)
if (!edge[s[j]][i]) add(s[j],i);
memset(yes,0,sizeof(yes));
}
for (int i=1;i<=n;i++) if (rd[i]==0) dfs(i,1);
for (int i=1;i<=n;i++) ans=max(dep[i],ans);
printf("%d\n",ans);
return 0;
}
by kingofpupil @ 2019-02-27 21:23:16
rt,Wonderful Answer