Pagini recente » Cod sursa (job #1621739) | Cod sursa (job #2274757) | Cod sursa (job #1628110) | Cod sursa (job #2108436) | Cod sursa (job #28170)
Cod sursa(job #28170)
var f,g:text;
x,y,z,w:array[1..1024] of boolean;
a,b:array[1..1024] of longint;
nr1,nr2,poz1,poz2,
n,i,j,k,l,m:longint;
begin
assign(f,'balanta.in');
reset(F);
assign(g,'balanta.out');
rewrite(G);
readln(f,n,m);
fillchar(x,n,true);
fillchar(y,n,true);
for l:=1 to m do
begin
read(f,k);
for i:=1 to k do
read(f,a[i]);
for i:=1 to k do
read(f,b[i]);
fillchar(w,n,false);
fillchar(z,n,false);
read(f,j);
if j=0 then
for i:=1 to k do
begin
x[b[i]]:=false;
x[a[i]]:=false;
y[a[i]]:=false;
y[b[i]]:=false;
end
else
if j=1 then
begin
for i:=1 to k do
begin
w[a[i]]:=true;
z[b[i]]:=true;
end;
for i:=1 to n do
begin
if x[i] and w[i] then
else x[i]:=false;
if y[i] and z[i] then
else y[i]:=false;
end;
end
else
begin
for i:=1 to k do
begin
w[b[i]]:=true;
z[a[i]]:=true;
end;
for i:=1 to n do
begin
if x[i] and w[i] then
else x[i]:=false;
if y[i] and z[i] then
else y[i]:=true;
end;
end;
end;
nr1:=0;
for i:=1 to n do
if x[i] then begin
nr1:=nr1+1;
poz1:=i;
end;
if nr1<>1 then
begin
nr2:=0;
for i:=1 to n do
if y[i] then
begin
nr2:=nr2+1;
poz2:=i;
end;
end;
if nr1=1 then
writeln(g,poz1)
else if nr2=1 then
writeln(g,poz2)
else writeln(g,0);
close(F);
close(G);
end.