Pagini recente » Cod sursa (job #2460314) | Cod sursa (job #2383710) | Cod sursa (job #1100308) | Cod sursa (job #799553) | Cod sursa (job #428203)
Cod sursa(job #428203)
var a:array[1..100,1..100] of boolean;
f,g:text;
fol:array[1..10000] of boolean;
dr,st:array[1..100] of longint;
m,x,y,i,nr,n,p:longint;
function cupleaza(nod:longint):boolean;
var i:longint;
begin
if fol[nod] then cupleaza:=false
else begin
fol[nod]:=true; cupleaza:=false;
for i:=1 to p do
if a[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,n,p,m);
for i:=1 to m do begin
read(f,x,y);
a[x,y]:=true;
end;
nr:=0;
for i:=1 to n do
if st[i]=0 then begin
if cupleaza(i) then nr:=nr+1
else begin
for i:=1 to n do
fol[i]:=false;
if cupleaza(i) then
nr:=nr+1;
end;
end;
writeln(g,nr);
for i:=1 to n do
if st[i]<>0 then
writeln(g,i,' ',st[i]);
close(g);
end.