Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- sz = 11;
- var
- c,f:array[0..sz,0..sz] of longint;
- q,cf,p:array[0..sz] of longint;
- i,j,n,m,s,e,u,v,w,st,fn,maxflow:longint;
- function min(a,b:longint):longint;
- begin
- if a < b then
- min:=a
- else min:=b;
- end;
- begin
- read(n,m);
- for i:=1 to m do
- begin
- read(u,v,w);
- c[u][v]:=w;
- end;
- read(st,fn);
- while True do
- begin
- fillchar(p,sizeof(p),0);
- s:=0; e:=0; q[0]:=st;
- cf[st]:=maxlongint;
- while (s <= e) do
- begin
- v:=q[s];
- for i:=1 to n do
- if (c[v][i] - f[v][i] > 0) and (p[fn] = 0) and (c[v][i] <> 0) then
- begin
- inc(e);
- q[e]:=i;
- p[i]:=v;
- cf[i]:=min(cf[v],c[v][i] - f[v][i]);
- end;
- inc(s);
- end;
- if p[fn] = 0 then
- break;
- u:=fn;
- while u <> st do
- begin
- inc(f[p[u]][u],cf[n]);
- dec(f[u][p[u]],cf[n]);
- u:=p[u];
- end;
- end;
- for i:=1 to n do
- if c[st][i] <> 0 then
- inc(maxflow,f[st][i]);
- writeln(maxflow);
- end.
Advertisement
Add Comment
Please, Sign In to add comment