讨论 / 为什么时间总是爆?/求大神指教
Hermione Granger 2016-11-08 06:31:41
点我顶贴 收藏 删除
const oo=maxlongint shr 1;

var

s,i,j,k,l,m,n,s2,ans,ss:longint;

a:array[0..1000+19,0..1000+19]of boolean;

d,tmp,tmp2:array[0..1000+19] of longint;

bo:boolean;

begin

readln(n,m);

for i:=1 to m do

begin

read(s);

for j:=1 to s do read(tmp[j]);

s2:=0;

for j:=1 to s-1 do

for k:=tmp[j]+1 to tmp[j+1]-1 do

begin

inc(s2);

tmp2[s2]:=k;

end;

for j:=1 to s do

for k:=1 to s2 do

a[tmp[j],tmp2[k]]:=true;

end;

fillchar(d,sizeof(d),0);

for i:=1 to n do

for j:=1 to n do

if a[j,i] then inc(d[i]);

fillchar(tmp,sizeof(tmp),0);

for i:=1 to n do

if d[i]=0 then

begin

inc(s);

tmp[s]:=i;

end;

for ans:=1 to oo do

begin

for i:=1 to n do

if d[i]>0 then break;

if d[i]=0 then break;

ss:=0;

for i:=1 to s do

for j:=1 to n do

if a[tmp[i],j] then

begin

a[tmp[i],j]:=false;

dec(d[j]);

if d[j]=0 then

begin

inc(ss);

tmp2[ss]:=j;

end;

end;

tmp:=tmp2;

s:=ss;

end;

writeln(ans);

end.

查看更多回复
提交回复