P
function find(t:longint):boolean;
var
i,q:longint;
begin
for i:=1 to n do
if (map[t,x[i]])and(not mark[x[i]]) then
begin
q:=link[x[i]];
link[x[i]]:=t;
mark[x[i]]:=true;
if (q=0)or(find(q)) then
exit(true);
link[x[i]]:=q;
end;
exit(false);
end;
fillchar(link,sizeof(link),0);
s:=0;
for i:=1 to m do
begin
fillchar(mark,sizeof(mark),false);
if find(y[i]) then
inc(s);
end;