无限orz hzwer神牛……

第一问很简单,按数据建图,然后一遍最大流算法即可。
    第二问则需要用最小费用最大流算法,主要是建图,那么可以从第一问的残留网络上继续建图,对残留网络上的每一条边建一条容量是∞费用是w的边(反向弧容量为0,费用为-w),然后建一个超级源点,从超级源向1建一条容量为k,费用为0的边,对这个图进行最小费用最大流算法。
    最小费用最大流操作:
    1.首先要对于这道题的图来说,有的边需要花费费用,而有的又不用,而不用扩容的边费用为0,需要扩容的边费用为w,容量无限,这就是本题这样建图的原因。
    2.对于残留网络进行费用最短路SPFA算法,不用扩容的边一定会选费用为0的边,然后记录路径,找最小容量对可行路进行增流,更新ans
——hzwer
 uses math;
const inf=maxlongint;
type node=record
from,go,v,c,t,next:longint;
end;
var i,n,m,k,t,u,v,w,c,s,cnt,ans:longint;
q,first,from,h,cur,d:array[..] of longint;
e:array[..] of node;
procedure ins(u,v,w,c:longint);
begin
inc(cnt);
e[cnt].go:=v;e[cnt].from:=u;
e[cnt].v:=w;e[cnt].t:=c;
e[cnt].next:=first[u];first[u]:=cnt;
end;
procedure insert(u,v,w,c:longint);
begin
ins(u,v,w,c);ins(v,u,,-c);
end;
procedure ins2(u,v,w,c:longint);
begin
inc(cnt);
e[cnt].go:=v;e[cnt].from:=u;
e[cnt].v:=w;e[cnt].c:=c;
e[cnt].next:=first[u];first[u]:=cnt;
end;
procedure insert2(u,v,w,c:longint);
begin
ins2(u,v,w,c);ins2(v,u,,-c);
end;
function bfs:boolean;
var head,tail,i,x,y:longint;
begin
head:=;tail:=;fillchar(h,sizeof(h),);
q[]:=s;h[s]:=;
while head<tail do
begin
inc(head);
x:=q[head];
i:=first[x];
while i<> do
begin
y:=e[i].go;
if (e[i].v<>) and (h[y]=) then
begin
h[y]:=h[x]+;
inc(tail);
q[tail]:=y;
end;
i:=e[i].next;
end;
end;
exit(h[t]<>);
end;
function dfs(x,f:longint):longint;
var i,tmp,used,y:longint;
begin
if x=t then exit(f);
tmp:=;used:=;
i:=cur[x];
while i<> do
begin
y:=e[i].go;
if (e[i].v<>) and (h[y]=h[x]+) then
begin
tmp:=dfs(y,min(f-used,e[i].v));
dec(e[i].v,tmp);
inc(e[i xor ].v,tmp);
inc(used,tmp);
if e[i].v<> then cur[x]:=i;
if used=f then exit(f);
end;
i:=e[i].next;
end;
if used= then h[x]:=-;
exit(used);
end;
procedure dinic;
begin
while bfs do
begin
for i:= to n do cur[i]:=first[i];
inc(ans,dfs(s,inf));
end;
end;
procedure build;
var tmp:longint;
begin
tmp:=cnt;
for i:= to cnt do
if i and = then insert2(e[i].from,e[i].go,inf,e[i].t);
end;
function spfa:boolean;
var i,x,y,head,tail:longint;
v:array[..] of boolean;
begin
head:=;tail:=;
for i:= to n do d[i]:=inf;
fillchar(v,sizeof(v),false);
q[]:=;d[]:=;v[i]:=true;
while head<tail do
begin
inc(head);
x:=q[head]; v[x]:=false;
i:=first[x];
while i<> do
begin
y:=e[i].go;
if (e[i].v>) and (d[x]+e[i].c<d[y]) then
begin
d[y]:=d[x]+e[i].c;
from[y]:=i;
if not(v[y]) then
begin
inc(tail);
q[tail]:=y;
v[y]:=true;
end;
end;
i:=e[i].next;
end;
end;
exit(d[n]<>inf);
end;
procedure mcf;
var i,x:longint;
begin
x:=inf;
i:=from[n];
while i<> do
begin
x:=min(x,e[i].v);
i:=from[e[i].from];
end;
i:=from[n];
while i<> do
begin
dec(e[i].v,x);
inc(e[i xor ].v,x);
i:=from[e[i].from];
end;
inc(ans,x*d[n]);
end;
procedure main;
begin
cnt:=;
readln(n,m,k);
for i:= to m do
begin
readln(u,v,w,c);
insert(u,v,w,c);
end;
ans:=;
s:=;t:=n;
dinic;
write(ans,' ');
ans:=;
build;
ins(,,k,);
while spfa do mcf;
writeln(ans);
end;
begin
main;
end.

ZJOI2010网络扩容的更多相关文章

  1. 【题解】Luogu P2604 [ZJOI2010]网络扩容

    原题传送门:P2604 [ZJOI2010]网络扩容 这题可以说是板题 给你一个图,先让你求最大流 再告诉你,每条边可以花费一些代价,使得流量加一 问至少花费多少代价才能使最大流达到k 解法十分简单 ...

  2. 洛谷 P2604 [ZJOI2010]网络扩容 解题报告

    P2604 [ZJOI2010]网络扩容 题目描述 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用.求: 1. 在不扩容的情况下,1到N的最大流: 2. ...

  3. [Luogu 2604] ZJOI2010 网络扩容

    [Luogu 2604] ZJOI2010 网络扩容 第一问直接最大流. 第二问,添加一遍带费用的边,边权 INF,超级源点连源点一条容量为 \(k\) 的边来限流,跑费用流. 大约是第一次用 nam ...

  4. BZOJ1834[ZJOI2010]网络扩容——最小费用最大流+最大流

    题目描述 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用. 求:  1.在不扩容的情况下,1到N的最大流:  2.将1到N的最大流增加K所需的最小扩容费用 ...

  5. 1834. [ZJOI2010]网络扩容【费用流】

    Description 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用. 求:  1.在不扩容的情况下,1到N的最大流:  2.将1到N的最大流增加K所需 ...

  6. BZOJ1834:[ZJOI2010]网络扩容——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=1834 https://www.luogu.org/problemnew/show/P2604#sub ...

  7. [洛谷P2604][ZJOI2010]网络扩容

    题目大意:给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用. 求: 1.在不扩容的情况下,1到N的最大流: 2.将1到N的最大流增加K所需的最小费用. 题解 ...

  8. bzoj1834 [ZJOI2010]网络扩容

    Description 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用.求: 1. 在不扩容的情况下,1到N的最大流: 2. 将1到N的最大流增加K所需的 ...

  9. [ZJOI2010]网络扩容

    OJ题号: BZOJ1834.洛谷2604 思路: 对于第一问,直接跑一遍最大流即可. 对于第二问,将每条边分成两种情况,即将每条边拆成两个: 不需扩容,即残量大于零时,相当于这条边费用为$0$: 需 ...

随机推荐

  1. DB2分区表删除和添加分区

    1.数据库版本 2.具体procedure DROP PROCEDURE DB2USER.TOOLS_PARTITION_TABLE_SHOW (VARCHAR ()); )) /********** ...

  2. (转)Mac OS X内核编程,MAC驱动开发资源汇总

    一.Mac  OS  X内核编程开发官方文档: I/O Kit Fundamentals: I/O Kit基础 - Mac OS X系统内核编程 https://developer.apple.com ...

  3. 解决未能从程序集xxx中加载类型System.ServiceModel.Activation.HttpModule的问题

    在IIS中运行网站时,出现错误: 未能从程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c ...

  4. C# asp Aspose.Cells 教程,包含增加勾选框,单元格,字体设置

    1,引用Aspose.Cells  dll 2,using Aspose.Cells; 3, Workbook excel = new Workbook(); string strFilePath = ...

  5. oracle查询和设置过期时间

    第一步:找到oracle 打开enterprise Manager Console如下图: 第二步,找到概要文件: sys 用户进入,找到你的数据库(如:ora8)-“安全性”-"用户&qu ...

  6. 2016 系统设计第一期 (档案一)MVC 引用 js css

    @Styles.Render("~/Bootstrap/css/bootstrap-theme.css") @Scripts.Render("~/jQuery/jquer ...

  7. vim中编写python代码使用python-mode和syntastic插件时警告(Warning)的消除

    问题: 在Vim使用了syntastic后,编写代码时,可以对代码错误和警告进行相对实时的了解,对编写代码有很大的帮助.同时这个插件和python-mode一起工作时,可以对python代码的编写提供 ...

  8. js学习之函数声明与函数表达式区别[原创]

    作为一名js初学者,与大家分享下.Javascript中有函数声明提升的功能,会优先编译函数声明部分.比如, ff(); function ff(){ alert("hello world. ...

  9. Apache2.2+php5.4在windows上配置实例

    这几天一直在win8.1上配置apache+php环境,网上看了很多文章,自己又犯了很多错误才配置成功,对新手来说真是有点小难. 自己打算把配置的详细过程写下来,好帮助其他新手快速配置. 在这里参考了 ...

  10. zoj 3725

    题意: n个格子排成一条直线,可以选择涂成红色或蓝色,问最少 m 个连续为红色的方案数. 解题思路: 应该是这次 ZOJ 月赛最水的一题,可惜还是没想到... dp[i] 表示前 i 个最少 m 个连 ...