Pagini recente » Cod sursa (job #1290998) | Cod sursa (job #2314359) | Cod sursa (job #2669276) | Cod sursa (job #1774065) | Cod sursa (job #84306)
Cod sursa(job #84306)
type vector=array[0..1025]of longint;
var h,l,a,b:vector;
n,m,i,j,k,r,rez,nr:longint;
function gasit(n:longint;v:vector):boolean;
var i:longint;
begin
gasit:=false;
for i:=1 to k do
if v[i]=n then
begin
gasit:=true;
exit;
end;
end;
begin
assign(input,'balanta.in');reset(input);
assign(output,'balanta.out');rewrite(output);
readln(n,m);
for i:=1 to n do
begin
h[i]:=1;
l[i]:=1;
end;
for j:=1 to m do
begin
read(k);
for i:=1 to k do
read(a[i]);
for i:=1 to k do
read(b[i]);
read(r);
if r=0 then
begin
for i:=1 to k do
begin
h[a[i]]:=0;
h[b[i]]:=0;
l[a[i]]:=0;
l[b[i]]:=0;
end;
end;
if r=1 then
begin
for i:=1 to n do
begin
if (gasit(i,a))and(h[i]=1) then
h[i]:=1
else
h[i]:=0;
if (gasit(i,b))and(l[i]=1) then
l[i]:=1
else
l[i]:=0;
end;
end;
if r=2 then
begin
for i:=1 to n do
begin
if (gasit(i,b))and(h[i]=1) then
h[i]:=1
else
h[i]:=0;
if (gasit(i,a))and(l[i]=1) then
l[i]:=1
else
l[i]:=0;
end;
end;
end;
for i:=1 to n do
begin
nr:=nr+h[i]+l[i];
if (h[i]=1)or(l[i]=1) then
rez:=i;
end;
if nr=1 then
writeln(rez)
else
writeln(0);
close(input);close(output);
end.