bzoj 1191 匈牙利算法
这道题是一个裸的二分图。
/************************************************************** Problem: 1191 User: Davidliu Language: Pascal Result: Accepted Time:8 ms Memory:256 kb****************************************************************///program bzoj 1191 匈牙利算法;var n,m :longint; last,other,pre :array[0..2022] of longint; link :array[0..1012] of longint; flag :array[0..1012] of boolean; l,i,j :longint; a,b :longint; ans :longint;procedure connect(x,y :longint);begin inc(l); pre[l]:=last[x]; last[x]:=l; other[l]:=y;end;procedure init;var i :longint;begin read(n,m); l:=0; for i:=1 to m do begin read(a,b); connect(i,a); connect(i,b); end;end;function find(x :longint):boolean;var i,p,q :longint;begin q:=last[x]; while q<>0 do begin p:=other[q]; if not flag[p] then begin flag[p]:=true;; if (link[p]=0) or (find(link[p])) then begin link[p]:=x; exit(true); end; end; q:=pre[q]; end; exit(false);end;procedure main;var i :longint;begin ans:=0; for i:=1 to m do begin fillchar(flag,sizeof(flag),false); if find(i) then inc(ans) else break; end; writeln(ans);end;begin init; main;end.

浙公网安备 33010602011771号