弱数据 Floyd
哥没用dfs哦

var n,sum,i,x,k,j:longint;bo:boolean;b:array[0..200,0..200]of boolean;
a:array[0..200]of boolean;
begin
readln(n);fillchar(b,sizeof(b),false);sum:=0;
fillchar(a,sizeof(a),true);
for i:=1 to n do
begin
read(x);
while(x<>0)do begin b[i,x]:=true;read(x);end;
end;
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if i<>j then
b[i,j]:=b[i,j]or(b[i,k]and b[k,j]);
for i:=1 to n do
if a[i] then
begin
for j:=1 to n do
if(j<>i)and b[i,j]and b[j,i] then a[j]:=false;
inc(sum);a[i]:=false;
end;
writeln(sum);
end.

1 条评论

  • @ 2016-02-04 21:02:34

    Floyed??为什么不用并查集+路径压缩?

  • 1

信息

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