Pagini recente » Cod sursa (job #2602502) | Cod sursa (job #2460536) | Cod sursa (job #1448907) | Cod sursa (job #2962857) | Cod sursa (job #25386)
Cod sursa(job #25386)
program balanta;
type sir=array[0..1030] of boolean;
sir1=array[0..1030] of integer;
var i,t,z,zz,x,na,m,nb,y,j,n,k,r:longint;
v:array[0..2050] of integer;
f,g:text;
a,b:sir; c:sir1;
procedure cat(var a,b:sir; var c:sir1;x1,y1,x2,y2:longint);
var aux,i:longint;
begin
aux:=0;
for i:=x1 to y1 do if c[v[i]]<>0 then begin
if (na=1) and(a[v[i]]=true) then c[v[i]]:=2;
if a[v[i]]=false then inc(aux); a[v[i]]:=true;
end;
na:=aux+na; aux:=0;
for i:=x2 to y2 do if c[v[i]]<>0 then begin
if (nb=1) and(b[v[i]]=true) then c[v[i]]:=2;
if b[v[i]]=false then inc(aux); b[v[i]]:=true;
end;
end;
procedure verif;
begin
if r=0 then begin
c[v[1]]:=0; c[v[2]]:=0;
if a[v[1]]=true then dec(na);
if b[v[1]]=true then dec(nb);
if a[v[2]]=true then dec(na);
if b[v[2]]=true then dec(nb);
a[v[1]]:=false; a[v[2]]:=false;
b[v[2]]:=false; b[v[1]]:=false;
end;
if r=1 then begin
if a[v[1]]=true then c[v[1]]:=2 else inc(na);
if b[v[2]]=true then c[v[2]]:=2 else inc(nb);
a[v[1]]:=true; b[v[2]]:=true;
end;
if r=2 then begin
if b[v[1]]=true then c[v[1]]:=2 else inc(nb);
if a[v[2]]=true then c[v[2]]:=2 else inc(na);
a[v[2]]:=true; b[v[1]]:=true;
end;
end;
begin
assign(f,'balanta.in'); reset(f);
assign(g,'balanta.out'); rewrite(g);
readln(f,n,m); na:=0; nb:=0;
for i:=1 to n do c[i]:=1;
for t:=1 to m do begin
read(f,k);
for i:=1 to 2*k do read(f,v[i]);
read(f,r);
if k=1 then verif
else begin
if r=0 then
for i:=1 to 2*k do begin
c[v[i]]:=0;
if a[v[i]]=true then dec(na);
if b[v[i]]=true then dec(nb);
a[v[i]]:=false; b[v[i]]:=false;
end;
if r=1 then cat(a,b,c,1,k,k+1,2*k);
if r=2 then cat(b,a,c,1,k,k+1,2*k);
end;
end;
z:=0; x:=0;
for i:=1 to n do begin
if c[i]=2 then begin inc(x); y:=i; end;
if c[i]=1 then begin inc(z); zz:=i; end;
end;
if x=1 then writeln(g,y)
else if (z=1) and(x=0) then writeln(g,zz) else writeln(g,0);
close(f); close(g);
end.