Pagini recente » Cod sursa (job #1194461) | Cod sursa (job #791277) | Cod sursa (job #2140274) | Cod sursa (job #3265850) | Cod sursa (job #241187)
Cod sursa(job #241187)
var rel:array[1..10000,1..10000] of boolean;
f,g:text;
util:array[1..10000] of boolean;
dr,st:array[1..10000] of longint;
m,x,y,i,nr,n1,n2:longint;
function cupleaza(nod:longint):boolean;
var i:longint;
begin
if util[nod] then cupleaza:=false
else begin
util[nod]:=true; cupleaza:=false;
for i:=1 to n2 do
if rel[nod,i] then
if (dr[i]=0) or (cupleaza(dr[i])) then begin
st[nod]:=i; dr[i]:=nod;
cupleaza:=true;
break;
end;
end;
end;
begin
assign(f,'cuplaj.in'); reset(f);
assign(g,'cuplaj.out'); rewrite(g);
read(f,n1,n2,m);
for i:=1 to m do begin
read(f,x,y);
rel[x,y]:=true;
end;
nr:=0;
for i:=1 to n1 do
if st[i]=0 then begin
if cupleaza(i) then inc(nr)
else begin
fillchar(util,sizeof(util),false);
if cupleaza(i) then
inc(nr);
end;
end;
writeln(g,nr);
for i:=1 to n1 do
if st[i]<>0 then
writeln(g,i,' ',st[i]);
close(f); close(g);
end.