poj2914 stoer wagner算法


求无向图的最小割。

所谓的神奇的奇葩的诡异的.............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.




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值