无限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. CentOS6.5 MySQL 配置设置总结笔记

    三.登录MySQL 登录MySQL的命令是mysql, mysql 的使用语法如下:  mysql [-u username] [-h host] [-p[password]] [dbname]  u ...

  2. EditorLineEnds.ttr 受影响的D版本 Delphi 8-2010

    http://stackoverflow.com/questions/25295980/delphi-2006-2010-error-cannot-create-file-c-users-admin- ...

  3. apache-2.4.12之虚拟主机配置问题与觖决办法

    apache-2.4.12基于域名访问的多虚拟主机配置 原始配置: <VirtualHost *:80> ServerAdmin kk@etiantian.org DocumentRoot ...

  4. uva401 - Palindromes结题报告

    题目地址 :  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_probl ...

  5. 插入排序(insertion_sort)

    最简单的排序算法,又称插值排序,原理类似于打扑克牌时把摸到的牌插入手中已有序牌的过程. void insertion_sort(int* A ,int n){ int i,j,key; ;i < ...

  6. iOS定位坐标转换工具-b

    坐标系介绍 首先介绍一下目前的定位坐标系统1.地球坐标 :( 代号:GPS.WGS84 )--- 有W就是世界通用的也就是原始坐标体系,这是国际公认的世界标准坐标体系: 使用 WGS84 坐标系统的产 ...

  7. [转载]MongoDB设置访问权限、设置用户

    MongoDB已经使用很长一段时间了,基于MongoDB的数据存储也一直没有使用到权限访问(MongoDB默认设置为无权限访问限制),今天特地花了一点时间研究了一下,研究成果如下: 注:研究成果基于W ...

  8. EasyUI Datagrid 取编辑修改后的内容

    <script type="text/javascript"> $(function () { $('#tt').datagrid({ iconCls: 'icon-e ...

  9. Host Definition

    Description: A host definition is used to define a physical server, workstation, device, etc. that r ...

  10. c++实现文本中英文单词和汉字字符的统计

    源代码下载:http://download.csdn.net/detail/nuptboyzhb/4987141 1.统计文本中汉字的频数,为后续的文本分类做基础.对于汉字的统计,需要判断读取的是否为 ...