- 银河英雄传说
- 2009-09-06 13:02:21 @
已经写了
Inc(js);
if js mod 10000 then writeln;
但是还是只有60!!!帮帮帮忙吧~~55555
2 条评论
-
wlzxczy LV 9 @ 2015-07-18 15:42:57
我是天才他爸
var s,m:string;
f,d,size:array[1..30000] of longint;
n,i,p,a,b,x,y:longint;
function find(x:longint):longint;
begin
if f[x]=x then exit(x);
find:=find(f[x]);
d[x]:=d[x]+d[f[x]];
f[x]:=find;
end;
begin
assign(input,'galaxy.in'); assign(output,'galaxy.out');
reset(input); rewrite(output);
readln(n);
for i:=1 to 30000 do
begin
f[i]:=i;
size[i]:=1;
d[i]:=0;
end;
for i:=1 to n do
begin
readln(s);
m:=s[1];
delete(s,1,2);
p:=pos(' ',s);
val(copy(s,1,p-1),a);
delete(s,1,p);
val(s,b);
if m='M' then
begin
x:=find(a);
y:=find(b);
d[x]:=d[x]+size[y];
size[y]:=size[y]+size[x];
size[x]:=0;
f[x]:=y;
end
else
begin
x:=find(a);
y:=find(b);
if x<>y then writeln(-1)
else writeln(abs(d[a]-d[b])-1);
end;
end;
close(input); close(output);
end. -
2009-09-06 13:23:24@
这破水题
I hate it!
- 1