Pagini recente » Cod sursa (job #386048) | Istoria paginii utilizator/cudrici_carina | Rating MARK PETRICA (MARK-PETRICA) | Cod sursa (job #171630) | Cod sursa (job #43503)
Cod sursa(job #43503)
var n,m,ip,ic,i,j,s:integer;
a,c,o,u,d:array[0..1025]of integer;
p:array[1..1024,0..1025]of integer;
f,g:text;
begin
assign(f,'balanta.in');
reset(f);
readln(f,n,m);
for i:=1 to m do begin
read(f,ic);
ic:=ic*2;
for j:=1 to ic do read(f,c[j]);
readln(f,s);
if s=0 then for j:=1 to ic do a[c[j]]:=1
else begin
ip:=ip+1;
p[ip]:=c;
p[ip,0]:=ic;
p[ip,1025]:=s;
for j:=1 to ic do o[c[j]]:=1;
end;
end;
assign(g,'balanta.out');
rewrite(g);
if ip=0 then begin
s:=0;
for i:=1 to n do begin
if a[i]=0 then ic:=i
else s:=s+1;
end;
if s=n-1 then write(g,ic)
else write(g,0);
end
else begin
for i:=1 to ip do begin
if p[i,1025]=1 then begin
for j:=1 to p[i,0] div 2 do d[p[i,j]]:=1;
for j:=j+1 to 2*j do u[p[i,j]]:=1;
end;
if p[i,1025]=2 then begin
for j:=p[i,0] div 2+1 to p[i,0]do d[p[i,j]]:=1;
for j:=1 to p[i,0] div 2 do u[p[i,j]]:=1;
end;
end;
for i:=1 to n do if a[i]=1 then begin
u[i]:=1;
d[i]:=1;
end;
s:=0;
for i:=1 to n do
if u[i]=1 then s:=s+1
else ic:=i;
if n-s=1 then write(g,ic)
else begin
s:=0;
for i:=1 to n do
if d[i]=1 then s:=s+1
else ic:=i;
if n-s=1 then write(g,ic)
else write(g,0);
end;
end;
close(g);
end.