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

📄 ac1272.pas

📁 uralcode
💻 PAS
字号:
program ural1272;
const
  maxn=10000;
var
  root:array[1..maxn]of word;
  n,k,i,x,y:word;
procedure pathcomp(x:word);
  var
    r,t:word;
  begin
    r:=x;
    while root[r]<>r do
      r:=root[r];
    while root[x]<>r do begin
      t:=root[x];
      root[x]:=r;
      x:=t;
    end;
  end;
begin
  read(n,k,i{i is useless});
  for i:=1 to n do
    root[i]:=i;
  dec(n);
  for i:=1 to k do begin
    read(x,y);
    pathcomp(x);pathcomp(y);
    if root[x]=root[y] then continue;
    dec(n);
    root[root[x]]:=root[y];
  end;
  writeln(n);
end.

⌨️ 快捷键说明

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