Cod sursa(job #28599)

Utilizator andrei_infoMirestean Andrei andrei_info Data 8 martie 2007 08:24:58
Problema Balanta Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 2.02 kb
//balanta infoarena
const nmax = 1025;

type sirbool = array[1..nmax] of boolean;
     sirint = array[1..nmax] of integer;
var n,m,k:integer;
    h,l:sirbool;
    a,b:sirint;

procedure intersectie(var h:sirbool; x:sirint);
var aux : sirbool;
    i:integer;
begin
fillchar(aux,sizeof(aux),false);
for i:=1 to k do
        if h[x[i]] then aux[x[i]]:=true;
h:=aux;
end;


procedure citire;
var i,j,rez:integer;
begin
assign(input,'balanta.in'); reset(input);
fillchar(h,sizeof(h),true); fillchar(l,sizeof(l),true);
readln(n,m);
for i:=1 to m do
        begin
        read(k);
        for j:=1 to k do
                read(a[j]);
        for j:=1 to k do
                read(b[j]);
        readln(rez);
        if rez = 0 then
                for j:=1 to k do
                        begin
                        h[a[j]]:=false; h[b[j]]:=false;
                        l[a[j]]:=false; l[b[j]]:=false;
                        end
        else
        if rez = 1 then
                begin
                intersectie(h,a);
                intersectie(l,b);
                end
        else
                begin
                intersectie(h,b);
                intersectie(l,a);
                end;
        end;

end;

procedure afis;
var i,cardh,cardl:integer;
begin
cardh:=0; cardl:=0;
for i:=1 to n do
        if h[i] then inc(cardh);
for i:=1 to n do
        if l[i] then inc(cardl);
if (cardh=1) and (cardl=0) then
  begin
        for i:=1 to n do
                if h[i] then
                        begin
                        writeln(i);
                        break;
                        end;
  end
else
if (cardh=0) and ( cardl=1) then
        begin
        for i:=1 to n do
                if l[i] then
                        begin
                        writeln(i);
                        break;
                        end;
        end
else
        writeln(0);
end;


begin
citire;
assign(output,'balanta.out'); rewriTe(output);
afis;
close(output);
end.