Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## pascal

Posted by jinzhihan at 2016-08-18 21:04:52 on Problem 1273
```const
maxn=210;
inf=1000000000;

type
edge=record
point,front,lim:longint;
end;

var
e:array[0..maxn*2] of edge;
n,m,cnt,i,x,y,z,maxflow:longint;

function min(x,y:longint):longint; inline;
begin
if x>y then min:=y else min:=x;
end;

begin
end;

function bfs:boolean;
var
i,h,t,u,p,po:longint;
begin
for i:=2 to n do mark[i]:=0;
h:=1; t:=1; q[1]:=1; mark[1]:=1;
while h<=t do
begin
while p>-1 do
begin
po:=e[p].point;
if (mark[po]=0) and (e[p].lim>0)
then
begin
mark[po]:=mark[u]+1;
inc(t); q[t]:=po;
end;
p:=e[p].front;
end;
inc(h);
end;
if mark[n]=0 then exit(false) else exit(true);
end;

procedure dinic(k,sum:longint);
var
p,po,temp:longint;
begin
if k=n then begin inc(maxflow,sum); exit; end;
if mark[k]=mark[n] then exit;
p:=cur[k];
while (p>-1) and (sum>0) do
begin
po:=e[p].point;
if (mark[po]=mark[k]+1) and (e[p].lim>0)
then
begin
temp:=maxflow;
dinic(po,min(sum,e[p].lim));
temp:=maxflow-temp;
dec(e[p].lim,temp);
inc(e[p xor 1].lim,temp);
dec(sum,temp);
end;
cur[k]:=p; p:=e[p].front;
end;
if sum>0 then cur[k]:=-1;
end;

begin
while not eof do
begin
cnt:=-1;
for i:=1 to n do head[i]:=-1;
for i:=1 to m do
begin
end;

maxflow:=0;
while bfs do dinic(1,inf);

writeln(maxflow);
end;
end.```

Followed by: