求无向图的最小割。
所谓的神奇的奇葩的诡异的.............stoer wagner算法,证明越看越错,只是,程序在poj上过了..........
反正觉得证明中的等号是不一定取得到的,而且初始条件无法理解,至于归纳过程倒是不难..........
一个资料:
http://www.docin.com/p-48578124.html
不断的用prim求类最大生成树,min一下最后加入的顶点的dist值,并合并最后键入的两个顶点,这样一直做(边数-1)次
无语中..........
直接贴代码算了(写丑了,用了8000多ms)
program lmd;
var
yes,del:array[0..500+5]of boolean;
vap:array[0..500+5]of longint;
map:array[0..500+5,0..500+5]of longint;
maxn,bj,i,j,n,m,last,cut,x,y,z,tot:longint;
begin
assign(input,'2914.in');
assign(output,'2914.out');
reset(input);rewrite(output);
while not seekeof do
begin
read(n,m);
fillchar(map,sizeof(map),0);
fillchar(del,sizeof(del),0);
for i:=1 to m do
begin
read(x,y,z);
inc(x); inc(y);
inc(map[x,y],z);
inc(map[y,x],z);
end;
cut:=maxlongint;
for tot:=n downto 2 do
begin
fillchar(yes,sizeof(yes),1);
fillchar(vap,sizeof(vap),0);
for i:=1 to tot-1 do
begin
maxn:=-1; bj:=0;
for j:=1 to n do
if (maxn<vap[j]) and (yes[j]) and (not del [j]) then
begin
maxn:=vap[j];
bj:=j;
end;
yes[bj]:=false;
for j:=1 to n do
if (yes[j]) and (not del [j]) then
vap[j]:=vap[j] + map[j,bj];
end;
for i:=1 to n do
if (not del[i]) and (yes[i]) then
begin
last:=i;
break;
end;
if vap[last]<cut then cut:=vap[last];
del[last]:=true;
for i:=0 to n do
if not del [i] then
begin
map[i,bj]:=map[i,bj]+map[i,last];
map[bj,i]:=map[i,bj];
end;
map[bj,bj]:=0;
end;
writeln(cut);
end;
close(input);close(output);
end.