ac1080.pas

来自「uralcode」· PAS 代码 · 共 44 行

PAS
44
字号
program ural1080;
const
  maxn=98;
var
  c:array[1..maxn]of shortint;
  adj:array[1..maxn,1..maxn]of boolean;
  n,i,x:byte;
procedure fail;
  begin
    writeln(-1);
    halt;
  end;
procedure color(v:byte;x:shortint);
  var
    i:byte;
  begin
    if c[v]>-1 then
      if c[v]=x then exit else fail;
    c[v]:=x;
    for i:=1 to n do
      if adj[v,i] then begin
        adj[v,i]:=false;adj[i,v]:=false;
        color(i,1-x);
      end;
  end;
begin
  fillchar(c,sizeof(c),255);
  fillchar(adj,sizeof(adj),0);
  readln(n);
  for i:=1 to n do
    repeat
      read(x);
      if x=0 then break;
      adj[i,x]:=true;adj[x,i]:=true;
    until false;

  for i:=1 to n do
    if c[i]=-1 then color(i,0);

  for i:=1 to n do
    write(c[i]);
  writeln;
end.

⌨️ 快捷键说明

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