Cod sursa(job #145872)

Utilizator CezarMocanCezar Mocan CezarMocan Data 29 februarie 2008 17:05:51
Problema Party Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.63 kb
type vacutza=record
                a,b:longint;
                end;
var n,m,i,j,k,rez,nr,cd:longint;
    v:array[1..1000] of longint;
    x:array[1..1000] of vacutza;

function eval(a,b:longint):longint;
var t1,t2:longint;
begin
t1:=v[abs(a)];
t2:=v[abs(b)];
if a<0 then
        t1:=1-t1;
if b<0 then
        t2:=1-t2;
eval:=(t1 or t2);
end;

begin
assign(input,'party.in');reset(input);
assign(output,'party.out');rewrite(output);
readln(n,m);
for i:=1 to m do
        begin
        readln(x[i].a,x[i].b,cd);
        case cd of
                1:x[i].b:=-x[i].b;
                2:x[i].a:=-x[i].a;
                3:begin x[i].a:=-x[i].a;x[i].b:=-x[i].b;end;
                end;
        end;
randomize;
for i:=1 to n do
        v[i]:=random(2);
nr:=0;
while 1>0 do
        begin
        rez:=1;
        for i:=1 to m do
                rez:=rez*eval(x[i].a,x[i].b);
        if rez=1 then
                begin
                for i:=1 to n do
                        if v[i]=1 then
                                inc(nr);
                writeln(nr);
                for i:=1 to n do
                        if v[i]=1 then
                                writeln(i);
                close(output);
                halt;
                end;
        for i:=1 to m do
                begin
                if eval(x[i].a,x[i].b)=0 then
                        if random(2)=1 then
                                v[abs(x[i].a)]:=1-v[abs(x[i].a)]
                        else
                                v[abs(x[i].b)]:=1-v[abs(x[i].b)]
                end;
        end;
close(input);close(output);
end.