Pagini recente » Cod sursa (job #153697) | Cod sursa (job #436286) | Cod sursa (job #1212987) | Cod sursa (job #898127) | Cod sursa (job #1536983)
{$R-}
type nd=^nod;
nod=record
val:word;
next:nd
end;
var f:text;
j,x,y,n,m,c,i:word;
k:longint;
l,r:array[1..10000]of word;
ver:array[1..10000]of boolean;
p,pp:nd;
g:array[1..10000]of nd;
function pairup(x:word):boolean;
var p:nd;
begin
if not ver[x]then
begin
ver[x]:=true;
p:=g[x];
while p<>nil do
begin
if r[p^.val]=0 then
begin
l[x]:=p^.val;
r[p^.val]:=x;
pairup:=true;
exit;
end;
p:=p^.next
end;
p:=g[x];
while p<>nil do
begin
if pairup(r[p^.val])then
begin
l[x]:=p^.val;
r[p^.val]:=x;
pairup:=true;
exit
end;
p:=p^.next
end;
pairup:=false
end
else
pairup:=false;
end;
begin
assign(f,'cuplaj.in');
reset(f);
read(f,n,m,k);
for i:=1 to k do
begin
read(f,x,y);
if (x<>0)and(y<>0)then
begin
new(p);
p^.val:=y;
p^.next:=g[x];
g[x]:=p;
end;
end;
close(f); c:=0;
for i:=1 to n do
if l[i]=0 then
begin
for j:=1 to n do
ver[j]:=false;
if pairup(i) then
inc(c);
end;
assign(f,'cuplaj.out');
rewrite(f);
writeln(f,c);
for i:=1 to n do
if l[i]<>0 then
writeln(f,i,' ',l[i]);
close(f);
end.