记录编号 20291 评测结果 AAAAAAAAAA
题目名称 罪犯问题D 最终得分 100
用户昵称 Gravatardonny 是否通过 通过
代码语言 Pascal 运行时间 0.988 s
提交时间 2010-10-22 19:04:57 内存使用 69.24 MiB
显示代码纯文本
program criminald;
type
  ss=record
    z:array[0..200,1..2]of longint;
  end;
var
  i,j,k,l,n,m:longint;
  a:array[1..50001]of ss;
  b:array[1..50001]of integer;
  c:char;
procedure go(x:longint);
var
  i,j,k:longint;
begin
  if a[x].z[0,1]>0 then
  begin
    for i:=1 to a[x].z[0,1] do
    begin
      if (b[x]=0)and(b[a[x].z[i,1]]=2) then
      begin
        b[a[x].z[i,1]]:=a[x].z[i,2];
        go(a[x].z[i,1]);
      end
      else
      if (b[x]=1)and(b[a[x].z[i,1]]=2) then
      begin
        if a[x].z[i,2]=1 then b[a[x].z[i,1]]:=0
        else b[a[x].z[i,1]]:=1;
        go(a[x].z[i,1]);
      end
    end;
  end;
end;
begin
  assign(input,'criminald.in');
  reset(input);
  assign(output,'criminald.out');
  rewrite(output);
  readln(n,m);
  for i:=1 to m do
  begin
    read(l);
    b[l]:=1;
  end;
  for i:=1 to n do
  begin
    if b[i]<>1 then b[i]:=2;
    a[i].z[0,1]:=0;
  end;
  readln;
  read(c);
  while c<>'E' do
  begin
    case c of
    'A':
    begin
      read(l);
      if b[l]=2 then writeln('Unknown')
      else if b[l]=1 then writeln('Yes')
      else if b[l]=0 then writeln('No');
    end;
    'S':
    begin
      readln(k,l);
      if (b[k]<2) and (b[abs(l)]=2) then
      begin
        if (b[k]=1)and(l<0) then b[abs(l)]:=1;
        if (b[k]=1)and(l>0) then b[l]:=0;
        if (b[k]=0)and(l<0) then b[abs(l)]:=0;
        if (b[k]=0)and(l>0) then b[l]:=1;
        go(abs(l));
      end
      else
      if (b[k]=2)and(b[abs(l)]<2) then
      begin
        if (b[abs(l)]=1)and(l<0) then b[k]:=1;
        if (b[abs(l)]=1)and(l>0) then b[k]:=0;
        if (b[abs(l)]=0)and(l<0) then b[k]:=0;
        if (b[abs(l)]=0)and(l>0) then b[k]:=1;
        go(k);
      end
      else
      begin
        inc(a[k].z[0,1]);
        inc(a[abs(l)].z[0,1]);
        a[abs(l)].z[a[abs(l)].z[0,1],1]:=k;
        a[k].z[a[k].z[0,1],1]:=abs(l);
        if l>0 then
          begin
            a[k].z[a[k].z[0,1],2]:=1;
            a[abs(l)].z[a[abs(l)].z[0,1],2]:=1;
          end
          else
          begin
            a[k].z[a[k].z[0,1],2]:=0;
            a[abs(l)].z[a[abs(l)].z[0,1],2]:=0;
          end;
      end;
    end;
    end;
    read(c);
  end;
  close(input);
  close(output);
end.