📄 ac1213.pas
字号:
program tju1213;
const
ships=30000;
var
root,len,front:array[1..ships]of word;
n,p,i,j:longint;
c:char;
procedure pathcomp(x:word);
var
r,t,f:word;
begin
r:=x;f:=0;while r<>root[r] do begin inc(f,front[r]);r:=root[r];end;
while x<>r do begin
dec(f,front[x]);inc(front[x],f);
t:=root[x];root[x]:=r;x:=t;
end;
end;
begin
repeat
for i:=1 to ships do begin
root[i]:=i;len[i]:=1;front[i]:=0;
end;
readln(n);
for p:=1 to n do begin
readln(c,i,j);
pathcomp(i);pathcomp(j);
case c of
'M':begin
front[root[i]]:=len[root[j]];
inc(len[root[j]],len[root[i]]);
root[root[i]]:=root[j];
end;
'C':if root[i]=root[j] then writeln(abs(front[i]-front[j])-1) else writeln(-1);
end;
end;
until seekeof;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -