Virtual Object
::
Programs
:: Поиск максимального паросочетания |
||||
Наша кнопка |
||||
Поиск максимального паросочетания в двудольном графе {$APPTYPE CONSOLE} var a:array [1..250,1..250] of 0..1; ⁄⁄ m*n b,c:array [1..250] of longint; f:array [0..250] of boolean; n,m,i,res:longint; x:longint; ⁄⁄--------------------------------------------------- function test(x:longint):boolean; var i:longint; begin test:=false; if f[x] then exit; f[x]:=true; for i:=1 to m do if (a[i,x]>0) and ((b[i]=0)or(test(b[i]))) then begin b[i]:=x; c[x]:=i; test:=true; exit; end; end; ⁄⁄--------------------------------------------------- begin assign(input,′input.txt′);reset(input); assign(output,′output.txt′);rewrite(output); readln(n,m); res:=0; fillchar(a,sizeof(a),0); for i:=1 to n do begin while not seekeoln(input) do begin read(x); a[x,i]:=1; end; readln; end; for i:=1 to n do begin fillchar(f,sizeof(f),false); f[0]:=true; if test(i) then inc(res); end; writeln(res); for i:=1 to 250 do if c[i]<>0 then writeln(i,′ ′,c[i]) end. |
||||
Object © 2004 - 2005. All rights reserved. |