Why do I get MLE?(1357K)
program ural1109;
const
max=1000;
var
g:array[1..max,1..max]of -1..1;
s,t,cx,cy:array[1..max]of boolean;
m,n,x,y:integer;
k,i:longint;
function path(u:integer):boolean;
var
i,j:integer;
begin
path:=false;
for j:=1 to n do
if (g[u,j]=1) and not t[j] then begin
t[j]:=true;
if not cy[j] then begin
g[u,j]:=-1;
cy[j]:=true;
path:=true;
exit;
end
else begin
i:=1;
while (g[i,j]>=0) and not s[i] and (i<=m) do inc(i);
if i<=m then begin
s[i]:=true;
if path(i) then begin
g[u,j]:=-1;
g[i,j]:=1;
path:=true;
exit;
end;
end;
end;
end;
end;
begin
fillchar(g,sizeof(g),0);
readln(m,n,k);
for i:=1 to k do begin
readln(x,y);
g[x,y]:=1;
end;
fillchar(cx,sizeof(cx),0);
fillchar(cy,sizeof(cy),0);
i:=0;y:=0;
repeat
inc(i);
if cx[i] then continue;
fillchar(s,sizeof(s),0);s[i]:=true;
fillchar(t,sizeof(t),0);
if path(i) then begin
cx[i]:=true;
inc(y);
i:=0;
end;
until i=m;
writeln(m+n-y);
end.