program ec12;
var
father:array[1..5001] of longint;
n,m,i,k,a,b,a1,b1:longint;
function getfather(u:longint):longint;
begin
if father[u]=u then
exit(u)
else
getfather:=getfather(father[u]);
father[u]:=getfather;
end;
procedure union(x,y:longint);
var
fx,fy:longint;
begin
fx:=getfather(x);
fy:=getfather(y);
if fx<>fy then
father[fx]:=fy;
end;
begin
readln(m,n,k);
for i:=1 to m do
father[i]:=i;
for i:=1 to n do
begin
readln(a,b);
if getfather(a)<>b then
union(a,b);
end;
for i:=1 to k do
begin
readln(a1,b1);
if getfather(a1)=getfather(b1) then
writeln('Yes')
else
writeln('No');
end;
end.
这是一个满分的程序。 但是,请注意:在读入时,我手误将“if getfather(a)<>getfather(b) then ”打成了"if getfather(a)=b then ",然后就莫名其妙的满分了,但如果改回来,就只有20分,求大神解答