1. Ford-Fulkerson标号算法(最简单的实现)
分别记录这一轮扩展过程中的每个点的前驱与到该节点的增广最大流量,从源点开始扩展,每次选择一个点(必须保证已经扩展到这个店),检查与它连接的所有边,并进行扩展,直到扩展到t。
Program Ford-Fulkerson;
const
fin='maxstream.in';
fout='maxstream.out';
maxn=1000;
max=1000000000;
type
labeltype=record
father,have:longint;
flag:boolean;
end;
maptype=record
c,f:longint;
end;
var
n,s,t,total:longint;
map:array[1..maxn,1..maxn]of maptype;
vetex:array[1..maxn,0..maxn]of longint;
information:array[1..maxn]of labeltype;
procedure init;
var
i,e,u,v,c:longint;
begin
assign(input,fin);assign(output,fout);
reset(input);rewrite(output);
readln(n,e,s,t);
for i:=1 to e do
begin
readln(u,v,c);
inc(vetex[u,0]);vetex[u,vetex[u,0]]:=v;
inc(map[u,v].c,c);
inc(vetex[v,0]);vetex[v,vetex[v,0]]:=u;
end;
end;
function min(a,b:longint):longint;
begin
if a
else exit(b);
end;
procedure calc;
i,j,m,d,v:longint;
begin
repeat
fillchar(information,sizeof(information),0);
information[s].father:=s;information[s].have:=max;{初始标号}
repeat
i:=1;
while (i<=n) and not((information[i].father<>0)
and(not information[i].flag)) do inc(i);{找到已标号单位检查的点}
if i>n then break;
for j:=1 to vetex[i,0] do{进行扩展}
if (information[vetex[i,j]].father=0)
and((map[i,vetex[i,j]].c<>0)or(map[vetex[i,j],i].c<>0)) then
begin
v:=vetex[i,j];
if (map[i,v].f