Pagini recente » Cod sursa (job #3274908) | Cod sursa (job #1129479) | Cod sursa (job #580333) | Cod sursa (job #1631287) | Cod sursa (job #300784)
Cod sursa(job #300784)
program flux;
type capacitate = record
max,can:longint;
end;
lista = ^articol;
articol = record
nr:longint;
u:lista;
c:capacitate;
end;
drum = ^muchie;
muchie = record
val:lista;
u:drum;
end;
var a,p:array [1..1000] of lista;
parinte,cap,g:array [0..1000] of longint;
fl,min,szd,aux,sursa,destinatie,i,j,n,m,x,y,c:longint;
saturat:array [1..1000] of boolean;
pr,d:drum;
done:boolean;
procedure df(nod:longint);
var i:word;
begin
if nod = destinatie then
begin
done:=true;
end;
for i:=1 to g[nod] do
begin
if done then
begin
a[nod]:=p[nod];
exit;
end;
if a[nod]^.c.max-a[nod]^.c.can > 0 then
begin
if a[nod]^.c.max-a[nod]^.c.can<min then
min:=a[nod]^.c.max-a[nod]^.c.can;
inc(szd);
d^.val := a[nod];
new(d^.u);
d:=d^.u;
df(a[nod]^.nr);
end;
a[nod]:=a[nod]^.u;
end;
a[nod]:=p[nod];
end;
begin
assign(input,'flux.in');
assign(output,'flux.out');
reset(input);
rewrite(output);
readln(n,m);
fillchar(g,sizeof(g),0);
readln(sursa,destinatie);
for i:=1 to n do
begin
new(a[i]);
p[i]:=a[i];
end;
for i:=1 to m do
begin
readln(x,y,c);
a[x]^.nr:=y;
a[x]^.c.max:=c;
a[x]^.c.can:=0;
new(a[x]^.u);
a[x]:=a[x]^.u;
inc(g[x]);
end;
for i:=1 to n do
a[i]:=p[i];
fl:=0;
parinte[sursa]:=0;
fillchar(saturat,sizeof(saturat),false);
cap[sursa]:=maxint;
min:=maxint;
szd:=0;
new(d);
done:=true;
pr:=d;
while done do
begin
done:=false;
df(sursa);
if done then
begin
d:=pr;
inc(fl,min);
for i:=1 to szd do
begin
inc(d^.val^.c.can,min);
d:=d^.u;
end;
min:=maxint;
szd:=0;
new(d);
pr:=d;
end;
end;
writeln(fl);
close(input);
close(output);
end.