Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 781 | Accepted: 373 |
Description
Input
Accepted answers to the poll question | Encoding |
I would be happy if at least one from i and j is elected. | +i +j |
I would be happy if at least one from i and j is not elected. | -i -j |
I would be happy if i is elected or j is not elected or both events happen. | +i -j |
I would be happy if i is not elected or j is elected or both events happen. | -i +j |
The input data are separated by white spaces, terminate with an end of file, and are correct.
Output
Sample Input
3 3 +1 +2 -1 +2 -1 -3 2 3 -1 +2 -1 -2 +1 -2 2 4 -1 +2 -1 -2 +1 -2 +1 +2 2 8 +1 +2 +2 +1 +1 -2 +1 -2 -2 +1 -1 +1 -2 -2 +1 -1
Sample Output
1 1 0 1
Hint
为何我的代码是错的:
var
a:array [1..2010,1..2010] of longint;
low,dfn,st,c,belong:array [1..2010] of longint;
v,f:array [1..2010] of boolean;
k:array [1..2000,1..2000] of boolean;
i,j,m,n,x,y,d,t,p,tt,c1,c2:longint;
fff:boolean;
function min(x,y:longint):longint;
begin
if x>y then
exit(y);
exit(x);
end;
function pp:longint;
begin
f[st[t]]:=false;
dec(t);
exit(st[t+1]);
end;
procedure add(x,y:longint);
begin
if k[x,y] then
begin
k[x,y]:=false;
inc(c[x]);
a[x,c[x]]:=y;
end;
end;
procedure check;
var
i:longint;
begin
for i:=1 to n do
if belong[tt-i]=belong[tt+i] then
begin
fff:=false;
exit;
end;
end;
procedure tarjan(x:longint);
var
i,y:longint;
begin
inc(d);
low[x]:=d;
dfn[x]:=d;
inc(t);
st[t]:=x;
f[x]:=true;
for i:=1 to c[x] do
begin
if not v[a[x,i]] then
begin
v[a[x,i]]:=true;
tarjan(a[x,i]);
low[x]:=min(low[x],low[a[x,i]]);
end else
begin
if f[a[x,i]] then
low[x]:=min(low[x],dfn[a[x,i]]);
end;
end;
if dfn[x]=low[x] then
begin
inc(p);
belong[x]:=p;
y:=x-1;
while x<>y do
begin
y:=pp;
belong[y]:=p;
end;
end;
end;
begin
while not eof do
begin
t:=0;
p:=0;
d:=0;
tt:=1005;
fillchar(belong,sizeof(belong),0);
fillchar(low,sizeof(low),0);
fillchar(dfn,sizeof(dfn),0);
fillchar(st,sizeof(st),0);
fillchar(f,sizeof(f),false);
fillchar(v,sizeof(v),false);
fillchar(a,sizeof(a),0);
fillchar(c,sizeof(c),0);
fillchar(k,sizeof(k),true);
read(n,m);
for i:=1 to m do
begin
read(x,y);
if x>0 then
begin
if y>0 then
begin
add(tt-x,tt+y);
add(tt-y,tt+x);
end else
begin
add(tt-x,tt-abs(y));
add(tt+abs(y),tt+x);
end;
end else
begin
if y>0 then
begin
add(tt+abs(x),tt+y);
add(tt-y,tt-abs(x));
end
else
begin
add(tt+abs(x),tt-abs(y));
add(tt+abs(y),tt-abs(x));
end;
end;
end;
for i:=1 to tt*2 do
if not v[i] then
begin
v[i]:=true;
tarjan(i);
end;
fff:=true;
check;
if fff then
writeln('1') else
writeln('0');
readln;
end;
end.