190040257a @ 2019-11-15 07:32:17
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
queue<int>P;
int hav[1035],ans;
bool sue[1045];
int cun[1034],de[1055],w[1044][1044];
int main()
{
int N,M;
int s;
scanf("%d%d",&N,&M);
for(int i=1;i<=M;i++)
{
memset(sue,0,sizeof(sue));
memset(cun,0,sizeof(cun));
scanf("%d",&s);
for(int k=1;k<=s;k++)
{
scanf("%d",cun+k);
cun[0]++;
sue[cun[k]]=1;
}
for(int j=cun[1];j<=cun[s];j++)
{
if(!sue[j])
{
for(int l=1;l<=s;l++)
{
if(!w[j][cun[l]])
{
de[cun[l]]++;
w[j][cun[l]]=1;
}
}
}
}
}
for(int s=1;s<=N;s++)
{
if(de[s]==0)
{
P.push(s);
}
}
while(!P.empty())
{
memset(hav,0,sizeof(hav));
while(!P.empty())
{
hav[0]++;
hav[hav[0]]=P.front();
P.pop();
}
for(int i=1;i<=hav[0];i++)
{
for(int j=1;j<=N;j++)
{
if(w[hav[i]][j])
{
de[j]--;
if(de[j]==0)
{
P.push(de[j]);
}
}
}
}
ans++;
}
cout<<ans;
return 0;
}
by 190040257a @ 2019-11-15 07:33:02
用的是邻接矩阵,因为实在是不会邻接表,麻烦大佬勿喷