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

📄 ac1162.pas

📁 同济大学 Online在线题库 AC源代码合集 程序设计竞赛必看资料
💻 PAS
字号:
program tju1162;
const
  maxn=200;
var
  root:array[1..sqr(maxn)]of word;
  n,m,i,x,y:word;
  c:char;
procedure pathcomp(x:word);
  var
    r,t:word;
  begin
    r:=x;while root[r]<>r do r:=root[r];
    while x<>r do begin t:=root[x];root[x]:=r;x:=t;end;
  end;
procedure test;
  begin
    read(n,m);
    for i:=1 to sqr(n) do root[i]:=i;
    for i:=1 to m do begin
      read(x,y);x:=(x-1)*n+y;
      readln(c,c);if c='D' then y:=x+n else y:=x+1;
      pathcomp(x);pathcomp(y);
      if root[x]=root[y] then begin
        for x:=i+1 to m do readln;writeln(i);exit;
      end
      else
        root[root[x]]:=root[y];
    end;
    writeln('draw');
  end;
begin
  repeat
    test;
  until seekeof;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -