program flow18;
const maxn=10000;
type
lin=record
u,v,w,c,pre,cap:longint;
end;
var
e:array[0..10000]of lin;
low,pre,d,last:array[0..110]of longint;
v:array[0..110]of boolean;
que:array[0..maxn]of longint;
n,m,cost,tot:longint;
function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end;
procedure addedge(u,v,w,c,cap:longint);
begin
inc(tot);
e[tot].u:=u;
e[tot].v:=v;
e[tot].w:=w;
e[tot].c:=c;
e[tot].cap:=cap;
e[tot].pre:=last[u];
last[u]:=tot;
end;
function spfa(s,t:longint):boolean;
var l,r,tmp,aug,u:longint;
begin
fillchar(que,sizeof(que),0);
fillchar(low,sizeof(low),0);
fillchar(pre,sizeof(pre),0);
fillchar(v,sizeof(v),false);
fillchar(d,sizeof(d),1);
l:=0;r:=1;que[l]:=s;
d[s]:=0;v[s]:=true;
low[s]:=maxlongint;low[t]:=low[s];
while l<>r do
begin
u:=que[l];
tmp:=last[u];
while tmp<>-1 do
begin
if (d[e[tmp].v]>d[u]+e[tmp].c)and(e[tmp].w>0) then
begin
d[e[tmp].v]:=d[u]+e[tmp].c;
pre[e[tmp].v]:=tmp;
low[e[tmp].v]:=min(low[u],e[tmp].w);
if not v[e[tmp].v] then
begin
que[r]:=e[tmp].v;
r:=(r+1)mod maxn;
v[e[tmp].v]:=true;
end;
end;
tmp:=e[tmp].pre;
end;
v[u]:=false;
l:=(l+1)mod maxn;
end;
if low[t]=maxlongint then exit(false);
cost:=cost+low[t]*d[t];
u:=t;aug:=low[t];
while u<>s do
begin
dec(e[pre[u]].w,aug);
inc(e[pre[u] xor 1].w,aug);
u:=e[pre[u]].u;
end;
exit(true);
end;
procedure init;
var i,j,k:longint;
begin
read(n);
fillchar(last,sizeof(last),255);
tot:=-1;
for i:=1 to n do
begin
addedge(0,i,1,0,1);
addedge(i,0,0,0,0);
end;
for i:=1 to n do
begin
addedge(i+n,n+n+1,1,0,1);
addedge(n+n+1,i+n,0,0,0);
end;
for i:=1 to n do
for j:=1 to n do
begin
read(k);
addedge(i,j+n,1,k,1);
addedge(j+n,i,0,-k,0);
end;
cost:=0;
while spfa(0,n+n+1) do;
writeln(cost);
cost:=0;
for i:=0 to tot do
begin
e[i].w:=e[i].cap;
e[i].c:=-e[i].c;
end;
while spfa(0,n+n+1) do;
writeln(-cost);
end;
begin
init;
end.
评论