实现功能:同最大流 1

这里面主要是把前面的邻接矩阵改成了邻接表,相比之下速度大大提高——本人实测,当M=1000000 N=10000 时,暂且不考虑邻接矩阵会不会MLE,新的程序速度快了很多倍(我们家这个很弱的电脑上耗时0.3s);而当M=300000 N=10000时,优势更加明显(几乎是秒出),别的没了,尤其当遇到稀疏图的时候这样子是大大划算的!!!

 type
point=^node;
node=record
g,w:longint;
next:point;
end; var
i,j,k,l,m,n,tmp,ans,aug,mi,s,t:longint;
di,a:array[..] of point;
pre,his,dis,vh:array[..] of longint;
flag:boolean;p,jl:point;
function min(x,y:longint):longint;inline;
begin
if x<y then min:=x else min:=y;
end;
function add(x,y,z:longint):longint;inline;
var p:point;
begin
new(p);p^.w:=z;p^.g:=y;
p^.next:=a[x];a[x]:=p;
end;
procedure op(x,y,z:longint);inline;
var p:point;
begin
p:=a[x];
while p<>nil do
begin
if (p^.g=y) and ((p^.w+z)>=) then
begin
p^.w:=p^.w+z;
break;
end;
p:=p^.next;
end;
end;
begin
readln(n,m,s,t);
for i:= to n do a[i]:=nil;
for i:= to m do
begin
readln(j,k,l);
add(j,k,l);add(k,j,);
end;
for i:= to n do di[i]:=a[i];
fillchar(dis,sizeof(dis),);
fillchar(pre,sizeof(pre),);
fillchar(his,sizeof(his),);
fillchar(vh,sizeof(vh),);
i:=s;vh[]:=n;ans:=;aug:=maxlongint;
while dis[s]<n do
begin
flag:=false;his[i]:=aug;
p:=a[i];
while p<>nil do
begin
if (p^.w>) and (dis[i]=(dis[p^.g]+)) then
begin
aug:=min(aug,p^.w);
pre[p^.g]:=i;di[i]:=p;
flag:=true;i:=p^.g;
if i=t then
begin
ans:=ans+aug;
while i<>s do
begin
tmp:=i;
i:=pre[i];
op(i,tmp,-aug);
op(tmp,i,aug);
end;
aug:=maxlongint;
end;
break;
end;
p:=p^.next;
end;
if flag then continue;
jl:=nil;mi:=n-;
p:=a[i];
while p<>nil do
begin
if (p^.w>) and (dis[p^.g]<mi) then
begin
jl:=p;mi:=dis[p^.g];
end;
p:=p^.next;
end;
di[i]:=jl;
dec(vh[dis[i]]);
if vh[dis[i]]= then break;
dis[i]:=mi+;
inc(vh[dis[i]]);
if i<>s then
begin
i:=pre[i];
aug:=his[i];
end;
end;
writeln(ans);
end.

最新文章

  1. HTML中块级元素与行内元素
  2. CSS的一些零碎总结
  3. Android EventBus实战 没听过你就out了
  4. 挑战程序2.1.4 穷竭搜索&gt;&gt;深度优先搜索
  5. sublime2的快捷键
  6. 一个PHP写的简单webservice服务端+客户端
  7. 【模版消息】C#推送微信模版消息(Senparc.Weixin.MP.dll)
  8. hihocoder#1054 : 滑动解锁(深度优先搜索)
  9. OpenJudge/Poj 1207 The 3n + 1 problem
  10. uboot 连接脚本分析
  11. [C#] - 注入DLL
  12. awk的+=用法
  13. 学习ASP.NET Core Razor 编程系列十六——排序
  14. 从输入URL到页面加载的全过程
  15. 【bzoj 3495】PA2010 Riddle
  16. django——中间件
  17. io.undertow.websockets.jsr.ServerWebSocketContainer cannot be cast to org.apache.tomcat.websocket.server.WsServerContainer
  18. jQuery事件学习
  19. P2707 Facer帮父亲
  20. [转] - spark推荐 - 从50多分钟到3分钟的优化

热门文章

  1. NamingException with message: Name [spring.liveBeansView.mbeanDomain]
  2. weblogic 集群部署时上传jsp不更新问题
  3. 【Unity3d游戏开发】游戏中的贝塞尔曲线以及其在Unity中的实现
  4. 访问 Neutron 外部网络 - 每天5分钟玩转 OpenStack(143)
  5. Eclipse TypeScript 安装
  6. Hadoop权威指南:FSDataInputStream对象
  7. 小学生之Hibernate插入数据修改数据使用数据库默认值的实现
  8. spring MVC cors跨域实现源码解析
  9. JavaScript从作用域到闭包
  10. Eclipse 报java.lang.UnsupportedClassVersionError: (&quot;yourclass&quot;) bad major version at offset=6