- 银河英雄传说
- 2010-07-08 21:03:16 @
我的程序是这个
怎么卡的
var
r,f,rr:array[1..30000]of longint;
n,i,j,k,l,t,x,y:longint;
c:char;
function find(x:longint):longint;
var
k:longint;
begin
if f[x]0 then
begin
k:=f[x];
f[x]:=find(f[x]);
r[x]:=r[x]+r[k];
exit(f[x]);
end
else
exit(x);
end;
begin
readln(t);
fillchar(r,sizeof(r),0);
fillchar(f,sizeof(f),0);
for i:=1 to 30000 do
rr[i]:=1;
for i:=1 to t do
begin
read(c);
if c='M' then
begin
readln(x,y);
if find(x)find(y) then
begin
x:=find(x);
y:=find(y);
f[y]:=x;
r[y]:=rr[x];
rr[x]:=rr[x]+rr[y];
rr[y]:=0;
end;
end
else
begin
readLN(x,y);
if find(x)find(y) then
writeln(-1)
else
begin
writeln(abs(r[y]-r[x])-1);
end;
end;
end;
end.
1 条评论
-
sunruoyang LV 8 @ 2015-12-30 11:50:25
,no,no,no,
- 1