比赛 |
“Asm.Def战记之夏威夷”杯 |
评测结果 |
AAAAWTTTTT |
题目名称 |
Asm.Def的报告 |
最终得分 |
40 |
用户昵称 |
Derrick_M |
运行时间 |
10.003 s |
代码语言 |
Pascal |
内存使用 |
1.31 MiB |
提交时间 |
2015-11-06 11:17:37 |
显示代码纯文本
program P2100;
var
a,b,c:array[1..100010] of longint;
n,m,i:longint;
procedure swap(var u,v:longint);
var
tmp:longint;
begin
tmp:=u;
u:=v;
v:=tmp;
end;
procedure qsort(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l;
j:=r;
x:=a[l+random(r-l+1)];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if not(i>j) then
begin
swap(a[i],a[j]);
swap(b[i],b[j]);
inc(i);
j:=j-1;
end;
until i>j;
if l<j then qsort(l,j);
if i<r then qsort(i,r);
end;
function dfs(u:longint):boolean;
var
va,vb:longint;
begin
if u=m+1 then exit(true);
if a[u]<0 then va:=0
else va:=1;
if b[u]<0 then vb:=0
else vb:=1;
if (c[abs(a[u])]=va xor 1) and (c[abs(b[u])]=vb xor 1) then exit(false);
if (c[abs(a[u])]=va) or (c[abs(b[u])]=vb) then
begin
if dfs(u+1) then exit(true);
exit(false);
end;
if (c[abs(a[u])]=-1) then
begin
c[abs(a[u])]:=va;
if dfs(u+1) then exit(true);
if (c[abs(b[u])]=-1) then
begin
c[abs(b[u])]:=vb;
if dfs(u+1) then exit(true);
c[abs(b[u])]:=-1;
end;
c[abs(a[u])]:=-1;
end
else
begin
c[abs(b[u])]:=vb;
if dfs(u+1) then exit(true);
c[abs(b[u])]:=-1;
end;
exit(false);
end;
begin
assign(input,'asm_report.in');assign(output,'asm_report.out');
reset(input);rewrite(output);
randomize;
readln(n,m);
for i:=1 to m do
begin
readln(a[i],b[i]);
if abs(a[i])>abs(b[i]) then swap(a[i],b[i]);
end;
qsort(1,m);
fillchar(c,sizeof(c),255);
dfs(1);
for i:=1 to n do
begin
if c[i]>=0 then write(c[i],' ')
else write('0 ');
end;
close(input);close(output);
end.