原题传送门http://www.lydsy.com/JudgeOnline/problem.php?id=1001
整理了下之前A的题
平面图可以转化成对偶图,然后(NlogN)的可以求出图的最小割(最大流)
算法合集有具体的讲解,有兴趣的可以在网上搜下或者向我要(QQ30056882)
/**************************************************************
Problem:
User: BLADEVIL
Language: Pascal
Result: Accepted
Time: ms
Memory: kb
****************************************************************/ //By BLADEVIL
var
n, m :longint;
pre, other, len, last :array[..] of longint;
l :longint;
heng, shu, xie :array[..,..] of longint;
tot :longint;
st, fin :longint;
que, d :array[..] of longint;
flag :array[..] of boolean; procedure connect(x,y,z:longint);
begin
inc(l);
pre[l]:=last[x];
last[x]:=l;
other[l]:=y;
len[l]:=z;
end; procedure init;
var
i, j :longint;
min :longint;
begin
read(n,m);
for i:= to n do
for j:= to m- do read(heng[i,j]); for i:= to n- do
for j:= to m do read(shu[i,j]); for i:= to n- do
for j:= to m- do read(xie[i,j]);
min:=maxlongint;
if (n=) or (m=) then
begin
for i:= to n do
for j:= to m do
begin
if heng[i,j]> then if min>heng[i,j] then min:=heng[i,j];
if shu[i,j]> then if min>shu[i,j] then min:=shu[i,j];
if xie[i,j]> then if min>xie[i,j] then min:=xie[i,j];
end;
writeln(min);
halt;
end;
tot:=*(m-)*(n-);
for i:= to tot do
if i mod = then
begin
if ((i mod (*(m-)))>) then
begin
connect(i,i+,shu[i div (*(m-))+,(i mod (*(m-))) div +]);
connect(i+,i,shu[i div (*(m-))+,(i mod (*(m-))) div +]);
end;
if (i-*m+>) then
if ((i mod (*(m-)))>) then
begin
connect(i,i-*m+,heng[i div (*(m-))+,(i mod (*(m-))) div ]);
connect(i-*m+,i,heng[i div (*(m-))+,(i mod (*(m-))) div ]);
end else
begin
connect(i,i-*m+,heng[i div (*(m-)),m-]);
connect(i-*m+,i,heng[i div (*(m-)),m-]);
end;
end else
begin
connect(i,i+,xie[i div (*(m-))+,((i mod (*(m-)))+) div ]);
connect(i+,i,xie[i div (*(m-))+,((i mod (*(m-)))+) div ]);
end;
st:=tot+; fin:=tot+;
for i:= to (m-) do
begin
connect(st,i*,heng[,i]);
connect(i*,st,heng[,i]);
end;
for i:= to (n-) do
begin
connect(st,i**(m-),shu[i,m]);
connect(i**(m-),st,shu[i,m]);
end;
connect(st,*(m-),shu[,m]);
connect(st,*(m-),heng[,m-]);
connect(*(m-),st,shu[,m]);
connect(*(m-),st,heng[,m-]);
for i:= to (m-) do
begin
connect((n-)**(m-)+*i-,fin,heng[n,i]);
connect(fin,(n-)**(m-)+*i-,heng[n,i]);
end;
for i:= to (n-) do
begin
connect(fin,(i-)**(m-)+,shu[i,]);
connect((i-)**(m-)+,fin,shu[i,]);
end;
connect(fin,(n-)**(m-)+,shu[(n-),]);
connect(fin,(n-)**(m-)+,heng[n,]);
connect((n-)**(m-)+,fin,shu[(n-),]);
connect((n-)**(m-)+,fin,heng[n,]);
end; procedure main;
var
i, j :longint;
h, t :longint;
cur :longint;
q, p :longint; begin
que[]:=st;
filldword(d,sizeof(d) div ,maxlongint div );
d[st]:=;
t:=; h:=;
while h<>t do
begin
h:=h mod +;
cur:=que[h];
flag[cur]:=false;
q:=last[cur];
while q<> do
begin
p:=other[q];
if d[cur]+len[q]<d[p] then
begin
d[p]:=d[cur]+len[q];
if not flag[cur] then
begin
t:=t mod +;
que[t]:=p;
flag[p]:=true;
end;
end;
q:=pre[q];
end;
end;
writeln(d[fin]);
end; begin
///assign(input,'stop.in'); reset(input);
///assign(output,'stop.out'); rewrite(output);
init;
main;
///close(output); close(output);
end.