- 家族
- 2014-10-19 11:14:02 @
var
m,n,p,i,a,b,fa,fb:integer;
f:array[1..5000]of integer;
function gf(s:integer):integer;
begin
if f[s]=s then exit(s)
else f[s]:=gf(f[s]);
exit(f[s]);
end;
begin
readln(n,m,p);
for i:=1 to n do f[i]:=i;
for i:=1 to m do
begin
readln(a,b);
if gf(a)<>gf(b) then
begin
fa:=gf(a); fb:=gf(b);
if fa<>fb then f[fa]:=fb;
end;
end;
for i:=1 to p do
begin
readln(a,b);
if gf(a)=gf(b) then
writeln('YES')
else
writeln('NO');
end;
end.
3 条评论
-
liyinghaowei LV 10 @ 2014-10-22 21:15:04
HEHE
-
2014-10-22 21:08:36@
大小写
-
2014-10-19 11:21:59@
啊啊啊啊好吧
- 1