BLMontgomery @ 2017-03-08 20:25:46
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int s[4005],rdu[4005],head[4005],stop[4005],lo[4005],loi=0,cnt=0;
struct node
{
int next,to;
}edge[1035000];
inline void add(int u,int g)
{
edge[++cnt].to = g;
edge[cnt].next = head[u];
head[u] = cnt;
}
bool b[4005],v[4005];
int main()
{
register int i,j,k,m,n,u,top,x;
memset(edge,0,sizeof(edge));
memset(head,0,sizeof(head));
scanf("%d%d",&n,&m);
for(i=1;i<=m;++i)
{
scanf("%d",&s[i]);
memset(v,0,sizeof(v));
for(j=0;j<s[i];++j)
{
scanf("%d",&u);
stop[j]=u;
v[u]=1;
}
for(k=0;k<s[i];++k)
{
for(j=stop[0]+1;j<stop[s[i]-1];++j)
{
if(!v[j])
{
add(stop[k],j);
rdu[j]++;//Èë¶È
}
}
}
}
x=0;
top=n;
while(top>0)
{
x++;
for(j=1;j<=n;++j)
{
if(!rdu[j])
{
top--;
rdu[j]=-9;
for(i=head[j];i;i=edge[i].next)
{
if(rdu[edge[i].to]>0) rdu[edge[i].to]--;
if(!rdu[edge[i].to])
{
lo[++loi]=edge[i].to;//ÒÔ±ãºóÃæÈÃËü±ä»Ø0
rdu[edge[i].to]=-4;
}
}
}
}
for(i=1;i<=loi;++i)
{
rdu[lo[i]]=0;
}
loi=0;
}
cout<<x;
return 0;
}
by bymlg001 @ 2017-09-17 21:48:27
加个二维数组去重,你加了好多重边