const maxn=100; maxq=100000; var p,c,f:array[1..maxn,1..maxn] of longint; dist,path:array[1..maxn] of longint; q:array[1..maxq] of longint; check:array[1..maxn] of 0..1; n,m:longint; mark:boolean; procedure init; var s,t,r,w,i,j:longint; begin readln (n); readln (m); for i:=1 to m do begin readln (s,t,r,w); c[s,t]:=r;p[s,t]:=w; end; end; procedure main; var i,j,a,r,l,k:longint; begin fillchar(f,sizeof(f),0); mark:=true; while mark do begin q[1]:=1;r:=0;l:=1; mark:=false; for i:=2 to n do dist[i]:=maxlongint; fillchar(check,sizeof(check),0);dist[1]:=0; fillchar(path,sizeof(path),0); while r0) or (c[q[r],i]<>0) then begin if (c[q[r],i]<>0) and (f[q[r],i]0) and (f[i,q[r]]<>0) and (dist[q[r]]-p[i,q[r]]0 then begin mark:=true; l:=n;a:=maxlongint; while l<>1 do begin k:=abs(path[l]); if path[l]>0 then begin if c[k,l]-f[k,l]1 do begin k:=abs(path[l]); if path[l]>0 then inc(f[k,l],a) else dec(f[l,k],a); l:=k; end; end; end; end; procedure print; var i,j,s:longint; begin s:=0;for i:=1 to n-1 do inc(s,f[i,n]); writeln (s); s:=0; for i:=1 to n do for j:=1 to n do inc(s,f[i,j]*p[i,j]); writeln (s); end; begin init; main; print; end. 最小费用最大流。 你的好长啊。··· 把程序看懂后自己可以化嘛。 我暂时找不到用边存储的题目。 化为边后不小心错了也有可能。