【正文】
:longint。begin readln(n,m)。 tt:=m。 for i:=1 to n do begin t:=0。 read(c[0])。 for j:=1 to c[0] do begin read(c[j])。 inc(t,c[j]+1)。 end。 build(0,i,1,1,mt+2)。 end。 tt:=n。 for i:=1 to m do begin t:=0。 read(c[0])。 for j:=1 to c[0] do begin read(c[j])。 inc(t,c[j]+1)。 end。 build(1,i,1,1,nt+2)。 end。 readln。end。procedure addpoint(x,y,flag:longint)。begin if f[x,y] then exit。 inc(r)。 q[r].x:=x。 q[r].y:=y。 q[r].f:=flag。 f[x,y]:=true。end。procedure disposeline(var s:state。 t,x,flag,mark:longint)。var i:longint。begin i:=s[t,0].r。 while i0 do begin s[s[t,i].u,i].d:=s[t,i].d。 s[s[t,i].d,i].u:=s[t,i].u。 if s[0,i].d=0 then if mark=0 then addpoint(x,i,flag) else addpoint(i,x,flag)。 i:=s[t,i].r。 end。end。procedure deletestate(var s:state。 t,x,flag,mark:longint)。var i:longint。begin i:=s[0,t].d。 while i0 do begin disposeline(a[mark,x,flag],i,x,1flag,mark)。 disposeline(a[mark,x,1flag],i,x,flag,mark)。 i:=s[i,t].d。 end。end。procedure work。var i,j:longint。begin l:=1。 r:=0。 for i:=1 to n do for j:=1 to m do begin if a[0,i,0][0,j].d=0 then addpoint(i,j,1)。 if a[0,i,1][0,j].d=0 then addpoint(i,j,0)。 if a[1,j,0][0,i].d=0 then addpoint(i,j,1)。 if a[1,j,1][0,i].d=0 then addpoint(i,j,0)。 end。 while l=r do begin map[q[l].x,q[l].y]:=q[l].f。 deletestate(a[0,q[l].x,1q[l].f],q[l].y,q[l].x,1q[l].f,0)。 deletestate(a[1,q[l].y,1q[l].f],q[l].x,q[l].y,1q[l].f,1)。 inc(l)。 end。end。procedure print。var i,j:longint。begin for i:=1 to n do begin for j:=1 to m do if map[i,j]=1 then write(39。..39。) else write(39。39。)。 writeln。 end。end。begin //assign(input,39。39。)。 reset(input)。 //assign(output,39。39。)。 rewrite(output)。 init。 work。 print。 writeln(max)。 close(output)。en