记录编号 20174 评测结果 AAAAAAAAAA
题目名称 罪犯问题D 最终得分 100
用户昵称 GravatarAchilles 是否通过 通过
代码语言 Pascal 运行时间 0.507 s
提交时间 2010-10-21 16:57:06 内存使用 3.62 MiB
显示代码纯文本
program criminald;
var
  n,m,i,temp,a,b,top:longint;
  c:char;
  l1,l2,next,data,head:array[1..200000]of longint;
  sz:array[1..50000]of shortint;
function last(a:longint):longint;
begin
  if next[a]=0 then last:=a else last:=last(next[a]);
end;
procedure find(a:longint);
var
  i:longint;
begin
  while true do
  begin
    if sz[l2[a]]=0 then begin
      sz[l2[a]]:=sz[l1[a]]*data[a];
      find(head[l2[a]]);
    end;
    a:=next[a];
    if a=0 then break;
  end;
end;
begin
  assign(input,'criminald.in');
  assign(output,'criminald.out');
  reset(input);
  rewrite(output);
  readln(n,m);
  fillchar(sz,sizeof(sz),0);
  for i:=1 to m do
  begin
    read(temp);
    sz[temp]:=1;
  end;
  readln;
  top:=0;
  fillchar(l1,sizeof(l1),0);
  fillchar(l2,sizeof(l2),0);
  fillchar(next,sizeof(next),0);
  fillchar(data,sizeof(data),0);
  fillchar(head,sizeof(head),0);
  while true do
  begin
    read(c);
    if c='E' then break;
    if c='A' then begin
      readln(temp);
      if sz[temp]=1 then writeln('Yes');
      if sz[temp]=-1 then writeln('No');
      if sz[temp]=0 then writeln('Unknown');
    end;
    if c='S' then begin
      readln(a,b);
      if (sz[a]=0)or(sz[abs(b)]=0) then begin
        top:=top+1;
        if head[a]=0 then begin
          head[a]:=top;
          l1[top]:=a;
          l2[top]:=abs(b);
          data[top]:=abs(b) div b*(-1);
        end
        else begin
          temp:=last(head[a]);
          next[temp]:=top;
          l1[top]:=a;
          l2[top]:=abs(b);
          data[top]:=abs(b) div b*(-1);
        end;
        top:=top+1;
        if head[abs(b)]=0 then begin
          head[abs(b)]:=top;
          l1[top]:=abs(b);
          l2[top]:=a;
          data[top]:=abs(b) div b*(-1);
        end
        else begin
          temp:=last(head[abs(b)]);
          next[temp]:=top;
          l1[top]:=abs(b);
          l2[top]:=a;
          data[top]:=abs(b) div b*(-1);
        end;
        if sz[a]<>0 then begin
          sz[abs(b)]:=sz[a]*data[top-1];
          find(head[abs(b)]);
        end
        else begin
          if sz[abs(b)]<>0 then begin
            sz[a]:=sz[abs(b)]*data[top];
            find(head[a]);
          end;
        end;
      end;
    end;
  end;
  close(input);
  close(output);
end.