2291 - L1551 的题解

回去原题
#阿门
var n,m,p,i,x,y,w1,w2:longint;
    father:array[0..10000] of longint;
function getfather(i:longint):longint;
begin
  if father[i]=i then getfather:=i
  else father[i]:=getfather(father[i]);
  getfather:=father[i];
end;
procedure union(i,j:longint);
var u,v,k:longint;
begin
  u:=getfather(i);v:=getfather(j);
  for k:=1 to n do
    if father[k]=u then father[k]:=v;
end;
begin
  readln(n,m,p);
  for i:=1 to n do father[i]:=i;
  for i:=1 to m do begin
    readln(x,y);union(x,y);
  end;
  for i:=1 to p do begin
    readln(x,y);w1:=getfather(x);w2:=getfather(y);
    if w1=w2 then writeln('Yes') else writeln('No');
  end;
end.