zoukankan      html  css  js  c++  java
  • poj1273 sap算法的模型

    简单基础网络流,用sap算法,不过这道题有多重边,被阴了,WA一次,还有就是这题有多组数据(居然没看到...)

    program poj1273;
    var
      n,m,i,j,i1,j1:integer;
      ans,min,p:longint;
      flag:boolean;
      g:array[1..200,1..200] of longint;
      fir,now,t,num,liu:array[0..200] of longint;(fir[i]是表示增广路i的前一个节点,now[i]是当前边的两个端点为i,now[i],t[i]是顶点数为i的节点的个数,num[i]是第i个节点的编号,liu[i]是当前节点1到i的流量
    procedure init;
    var
      x,y,z:longint;
    begin
      readln(m,n);
      for i:=1 to m do
      begin
        readln(x,y,z);
        inc(g[x,y],z);
      end;
    end;
    begin
      while not eof do
      begin
        fillchar(g,sizeof(g),0);
        fillchar(fir,sizeof(fir),0);
        fillchar(now,sizeof(now),0);
        fillchar(t,sizeof(t),0);
        fillchar(num,sizeof(num),0);
        fillchar(liu,sizeof(liu),0);
        init;
        t[0]:=n;
        for i:=1 to n do
          now[i]:=1;
        ans:=0;
        i:=1;
        p:=maxlongint;
        while num[i]<n do
        begin
          flag:=false;
          liu[i]:=p;
          for j:=now[i] to n do
            if (g[i,j]>0) and (num[j]+1=num[i]) then
            begin
              flag:=true;
              if g[i,j]<p then p:=g[i,j];
              fir[j]:=i;
              now[i]:=j;
              i:=j;
              if i=n then
              begin
                inc(ans,p);
                while i<>1 do
                begin
                  i1:=i;
                  i:=fir[i];
                  dec(g[i,i1],p);
                  inc(g[i1,i],p);
                end;
                p:=maxlongint;
              end;
              break;
            end;
          if flag then continue;
          min:=n-1;//没有允许弧了,需要重标号
          for j:=1 to n do
            if (g[i,j]>0) and (num[j]<min) then
            begin
              j1:=j;
              min:=num[j];
            end;
          now[i]:=j1;
          dec(t[num[i]]);//GAP优化
          if t[num[i]]=0 then break;
          num[i]:=min+1;
          inc(t[num[i]]);
          if i<>1 then
          begin
            i:=fir[i];
            p:=liu[i];
          end;
        end;
        writeln(ans);
      end;
    end.

  • 相关阅读:
    mysql数据库监控利器lepus天兔工具安装和部署
    通过zabbix自带api进行主机的批量添加操作
    svn服务器的搭建备份和还原和svnmanager的使用
    elasticsearch自动按天创建索引脚本
    nginx或者squid正向代理实现受限网站的访问
    mysql查询sending data占用大量时间的问题处理
    解决由腾讯qq浏览器引起win10系统桌面图标不停的闪烁问题
    缓存系列之四:redis持久化与redis主从复制
    缓存系列之三:redis安装及基本数据类型命令使用
    缓存系列之二:CDN与其他层面缓存
  • 原文地址:https://www.cnblogs.com/stmq/p/2567311.html
Copyright © 2011-2022 走看看