记录编号 |
19908 |
评测结果 |
AWWWWWWWWW |
题目名称 |
罪犯问题D |
最终得分 |
10 |
用户昵称 |
苏轼 |
是否通过 |
未通过 |
代码语言 |
Pascal |
运行时间 |
1.568 s |
提交时间 |
2010-10-19 11:18:31 |
内存使用 |
1.26 MiB |
显示代码纯文本
program criminald(input,output);
type
node=record
be,next:longint;
end;
re=record
head,tail:longint;
end;
var
m,n,a,i:longint;
com:char;
t:array[0..50000]of node;
se:array[-50001..50001]of re;
procedure add(i,tp:longint);
begin
t[i].be:=tp;
if se[tp].head<>0 then
t[se[tp].tail].next:=i
else
se[tp].head:=i;
se[tp].tail:=i;
t[i].next:=0;
end;
procedure ask;
var
a:longint;
begin
readln(a);
case t[a].be of
50001:
writeln('Yes');
-50001:
writeln('No');
else
writeln('Unknown');
end;
end;
procedure swap(var a,b:longint);
var
t:longint;
begin
t:=a;
a:=b;
b:=t;
end;
procedure cover(a,b:longint);
var
i:longint;
begin
t[se[a].tail].next:=se[b].head;
i:=se[b].head;
se[b].head:=0;
while i<>0 do
begin
t[i].be:=a;
i:=t[i].next;
end;
se[b].tail:=0;
end;
procedure get_word;
var
a,b,ta,tb,pnt:longint;
diff:boolean;
begin
readln(a,b);
diff:=b>0;
b:=abs(b);
if (abs(t[b].be)=50001) then
begin
swap(a,b);
if (abs(t[b].be)=50001) then
exit;
end;
ta:=t[a].be;
tb:=t[b].be;
if diff then
ta:=-ta;
if ta=tb then
exit;
cover(ta,tb);
cover(-ta,-tb);
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(a);
add(a,50001);
end;
for i:=1 to n do
if t[i].be=0 then
add(i,i);
readln;
repeat
read(com);
case com of
'S':get_word;
'A':ask;
end;
until com='E';
close(input);
close(output);
end.