⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ac1213.pas

📁 同济大学 Online在线题库 AC源代码合集 程序设计竞赛必看资料
💻 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 + -