/ Vijos / 讨论 / 家族 /

哪错了? 谁能告诉我?

只得了20分

const

maxn=5000;

var

father:array[1..maxn] of integer;

t,n,m,p,i,x,y,fx,fy:integer;

function get(x:integer):integer;

begin

if father[x]=0 then

exit(x);

father[x]:=get(father[x]);

get:=father[x];

end;

begin

read(n,m,p);

fillchar(father,sizeof(Father),0);

for i:=1 to m do

begin

read(x,y);

fx:=get(x);

fy:=get(y);

if fxfy then

father[y]:=x;

end;

for i:=1 to n do

t:=get(i);

for i:=1 to p do

begin

read(x,y);

fx:=get(x);

fy:=get(y);

if fx=fy then

writeln('Yes')

else

writeln('No');

end;

end.

0 条评论

目前还没有评论...

信息

ID
1034
难度
4
分类
数据结构 | 并查集 点击显示
标签
(无)
递交数
9368
已通过
3839
通过率
41%
被复制
15
上传者