用bfs连续四次wa

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,掌握的不好,勿喷,每次都是过一个数据。实在是想不明白错哪了,求大神解

0 条评论

目前还没有评论...

信息

ID
1022
难度
4
分类
图结构 点击显示
标签
递交数
4326
已通过
1981
通过率
46%
被复制
13
上传者