Cod sursa(job #761605)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 26 iunie 2012 19:03:15
Problema Balanta Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.95 kb
Program balanta;
 var h,l,aux1,aux2:array [1..1024] of boolean;
     i,n,rez,j,n1,nr1,nr2,p1,p2,m:longint;
     fi,fo:text;
begin
 assign(fi,'balanta.in');
  assign(fo,'balanta.out');
 reset(fi); rewrite(fo); readln(fi,n,m);
  for i:=1 to n do begin h[i]:=true; l[i]:=true; end;
  for j:=1 to m do begin
                   read(fi,n1);
                    for i:=1 to n1 do begin read(fi,rez); aux1[rez]:=true; end;
                    for i:=1 to n1 do begin read(fi,rez); aux2[rez]:=true; end;
                   readln(fi,rez);
                   if rez=0 then for i:=1 to n do begin
                                       if ((aux1[i]=true) or (aux2[i]=true)) and (h[i]=true) then h[i]:=false;
                                       if ((aux1[i]=true) or (aux2[i]=true)) and (l[i]=true) then l[i]:=false;
                                       aux1[i]:=false; aux2[i]:=false;
                                                   end
                   else if rez=1 then for i:=1 to n do begin
                                       if (aux1[i]=false) and (h[i]=true) then h[i]:=false;
                                       if (aux2[i]=false) and (l[i]=true) then l[i]:=false;
                                       aux1[i]:=false; aux2[i]:=false;
                                                    end
                   else for i:=1 to n do begin
                                       if (aux2[i]=false) and (h[i]=true) then h[i]:=false;
                                       if (aux1[i]=false) and (l[i]=true) then l[i]:=false;
                                       aux1[i]:=false; aux2[i]:=false;
                                          end;
                   end;
   for i:=1 to n do begin
    if h[i]=true then begin inc(nr1); p1:=i; end;
    if l[i]=true then begin inc(nr2); p2:=i; end;
                    end;
  if (nr1=1) and (nr2=0) then write(fo,p1)
  else if (nr2=1) and (nr1=0) then write(fo,p2)
   else write(fo,'0');
  close(fo);
end.