# 网络吞吐量

192人阅读 评论(0)

## 题目

7 10
1 2 2
1 5 2
2 4 1
2 3 3
3 7 1
4 5 4
4 3 1
4 6 1
5 6 2
6 7 1
1
100
20
50
20
60
1

70
n<=500,m<=100000,c,d<=109$10^9$

## 分析

const maxl=10000000000000;
var
nu,n,m,i,x,y,z,num,ni:longint;ans:int64;
b,last,next,v,las,nex,b1,re:array[1..200000] of longint;
f:array[1..200000] of int64;
bz:array[1..505] of boolean;
dis:array[1..505] of int64;
vh,h:array[0..1005] of longint;
a:array[1..1000000] of longint;
procedure insert(x,y,z:longint);
begin
inc(nu);b[nu]:=y;next[nu]:=last[x];last[x]:=nu;v[nu]:=z;
end;
begin
inc(num);b1[num]:=y;nex[num]:=las[x];las[x]:=num;f[num]:=z;
inc(num);b1[num]:=x;nex[num]:=las[y];las[y]:=num;f[num]:=0;re[num-1]:=num;re[num]:=num-1;
end;
procedure spfa;
var p,l,r,now,i:longint;
begin
fillchar(dis,sizeof(dis),127);
a[1]:=1;bz[a[1]]:=true;l:=0;r:=1;dis[a[1]]:=0;
while l<>r do begin
inc(l);now:=a[l];
p:=last[now];
while p<>0 do begin
if dis[b[p]]>dis[now]+v[p] then begin
dis[b[p]]:=dis[now]+v[p];
if not bz[b[p]] then begin
bz[b[p]]:=true;
inc(r);a[r]:=b[p];
end;
end;
p:=next[p];
end;
bz[now]:=false;
end;
for i:=1 to n do begin
p:=last[i];
while p<>0 do begin
if dis[b[p]]=dis[i]+v[p] then begin
else
end;
p:=next[p];
end;
end;
for i:=1 to n do begin
if (i=1)or(n=1) then continue;
end;
end;
function min(l,r:int64):int64;
begin
if l<r then exit(l);exit(r);
end;
function sap(x:longint;y:int64):int64;
var minh,p,t:longint;
begin
if x=n then exit(y);
minh:=ni+1;p:=las[x];
while p<>0 do begin
if f[p]>0 then begin
if h[x]=h[b1[p]]+1 then begin
t:=sap(b1[p],min(y,f[p]));
if t>0 then begin
f[p]:=f[p]-t;
f[re[p]]:=f[re[p]]+t;
exit(t);
end;
if h[1]>ni then exit(0);
end;
minh:=min(minh,h[b1[p]]+1);
end;
p:=nex[p];
end;
dec(vh[h[x]]);
if vh[h[x]]=0 then h[1]:=ni+1;
h[x]:=minh;
inc(vh[h[x]]);
exit(0);
end;
begin
assign(input,'network.in');reset(input);
assign(output,'network.out');rewrite(output);
for i:=1 to m do begin
insert(x,y,z);
insert(y,x,z);
end;
spfa;
ni:=n*2;vh[0]:=ni;
while h[1]<=ni do
ans:=ans+sap(1,maxl);
writeln(ans);
end.
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：37300次
• 积分：1345
• 等级：
• 排名：千里之外
• 原创：93篇
• 转载：1篇
• 译文：0篇
• 评论：6条
文章分类
评论排行
最新评论