- Victoria的舞会2
- 2015-08-16 23:53:11 @
var
p:array [1..200,1..200] of boolean;
a:array [1..200] of integer;
use:array [1..200] of boolean;
m,i,s,num,head,tail,j,n:integer;
pd:boolean;
begin
fillchar(p,sizeof(p),false);
fillchar(use,sizeof(use),true);
readln(n);
for i:=1 to n do
begin
read(s);
while s<>0 do
begin
p[i,s]:=true;
read(s);
end;
end;
num:=1;
head:=0;
tail:=1;
a[1]:=1;
m:=1;
num:=1;
use[1]:=false;
while head<>n do
begin
inc(head);
for i:=1 to n do
if p[a[head],i] and use[i] then
begin
pd:=true;
for j:=num to tail do
if (p[a[j],i]=false) or (p[i,a[j]]=false) then
begin
pd:=false;
break;
end;
if pd then
begin
inc(tail);
a[tail]:=i;
use[i]:=false;
end;
end;
if (head=tail) and (head<>n) then
begin
inc(m);
for i:=1 to n do
if use[i] then
begin
inc(tail);
a[tail]:=i;
use[i]:=false;
num:=tail;
break;
end;
end;
end;
writeln(m);
end.
RT,代码在上面,表示新学BFS,掌握的不好,勿喷,每次都是过一个数据。实在是想不明白错哪了,求大神解