比赛 10.10.18noip模拟 评测结果 EWEEEEEEEE
题目名称 罪犯问题D 最终得分 0
用户昵称 ZhouZn1 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-10-18 21:52:25
显示代码纯文本
program criminald;
var
        m,n,i,j,x,y,head,tail:longint;
        ch1,ch2,ch3:char;
        list,sure,peo:array[1..50000]of integer;
        v:array[1..50000]of boolean;
procedure init;
begin
        assign(input,'criminald.in');
        reset(input);
        assign(output,'criminald.out');
        rewrite(output);
        fillchar(sure,sizeof(sure),0);
        fillchar(v,sizeof(v),0);
        readln(n,m);
        for i:=1 to m do
         begin
             readln(j);
             v[j]:=true;
             sure[j]:=1;
             list[i]:=j;
         end;
        head:=0;
        tail:=m;
        fillchar(peo,sizeof(peo),0);
end;
procedure closef;
begin
        close(input);
        close(output);
end;
procedure bfs;
var
        now:integer;
        flg:boolean;
begin
    inc(head);
    flg:=false;
    now:=list[head];
    if head<=tail then
     begin
         repeat
         if peo[now]<0 then
          begin
              inc(tail);
              list[tail]:=abs(peo[now]);
              if v[-peo[x]]then dec(tail) else v[-peo[now]]:=true;
              sure[abs(peo[now])]:=1;
          end;
         if peo[now]>0 then
          begin
              sure[peo[now]]:=2;
          end;
         if peo[now]=0 then dec(head);
         until (head>=tail)or(head=0);
     end;
end;
procedure main;
begin
        while not(eoln)do
         begin
         bfs;
          read(ch1);
           if ch1='A' then
            begin
                read(x);
                if sure[x]=1 then writeln('Yes');
                if sure[x]=2 then writeln('No');
                if sure[x]=0 then writeln('Unknown');
            end;

         if ch1='E' then exit;
         if ch1='S' then
          begin
              read(x,y);
              peo[x]:=y;
              if sure[x]=2 then
               begin
                   if peo[x]<0 then
                    begin
                        sure[-peo[x]]:=2;
                    end;
                   if peo[x]>0 then
                    begin
                        inc(tail);
                        list[tail]:=peo[x];
                        if v[peo[x]]then dec(tail) else v[y]:=true;
                        sure[peo[x]]:=1;
                    end;
               end;
          end;
         readln;
        end;
end;
begin
        init;
        main;
        closef;
end.