Pagini recente » Cod sursa (job #2297061) | Cod sursa (job #2217126) | Cod sursa (job #3268140) | Cod sursa (job #1194206) | Cod sursa (job #1536986)
{$R-}
type nd=^nod;
nod=record
val:word;
next:nd
end;
var f:text;
j,x,y,n,c,i:word;
k:longint;
l,r:array[1..10000]of word;
ver:array[1..10000]of boolean;
p: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.