ZJOI2010网络扩容
无限orz 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网络扩容的更多相关文章
- 【题解】Luogu P2604 [ZJOI2010]网络扩容
原题传送门:P2604 [ZJOI2010]网络扩容 这题可以说是板题 给你一个图,先让你求最大流 再告诉你,每条边可以花费一些代价,使得流量加一 问至少花费多少代价才能使最大流达到k 解法十分简单 ...
- 洛谷 P2604 [ZJOI2010]网络扩容 解题报告
P2604 [ZJOI2010]网络扩容 题目描述 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用.求: 1. 在不扩容的情况下,1到N的最大流: 2. ...
- [Luogu 2604] ZJOI2010 网络扩容
[Luogu 2604] ZJOI2010 网络扩容 第一问直接最大流. 第二问,添加一遍带费用的边,边权 INF,超级源点连源点一条容量为 \(k\) 的边来限流,跑费用流. 大约是第一次用 nam ...
- BZOJ1834[ZJOI2010]网络扩容——最小费用最大流+最大流
题目描述 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用. 求: 1.在不扩容的情况下,1到N的最大流: 2.将1到N的最大流增加K所需的最小扩容费用 ...
- 1834. [ZJOI2010]网络扩容【费用流】
Description 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用. 求: 1.在不扩容的情况下,1到N的最大流: 2.将1到N的最大流增加K所需 ...
- BZOJ1834:[ZJOI2010]网络扩容——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=1834 https://www.luogu.org/problemnew/show/P2604#sub ...
- [洛谷P2604][ZJOI2010]网络扩容
题目大意:给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用. 求: 1.在不扩容的情况下,1到N的最大流: 2.将1到N的最大流增加K所需的最小费用. 题解 ...
- bzoj1834 [ZJOI2010]网络扩容
Description 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用.求: 1. 在不扩容的情况下,1到N的最大流: 2. 将1到N的最大流增加K所需的 ...
- [ZJOI2010]网络扩容
OJ题号: BZOJ1834.洛谷2604 思路: 对于第一问,直接跑一遍最大流即可. 对于第二问,将每条边分成两种情况,即将每条边拆成两个: 不需扩容,即残量大于零时,相当于这条边费用为$0$: 需 ...
随机推荐
- c语言指针用法
一.指针 int t 定义整型变量 int *p p为指向整型数据的指针变量 int a[n] 定义整型数组a,它有n个元素 int *p[n] 定义指针数组p,它由n个指向整形数据的指针元素组成 i ...
- 实现c++的string的split功能
今天写程序,遇到了一个要实现string.split()这个的一个函数.python里面有,qt里面有,c++里面没有.照着网上抄了一个,放在这里.有需要的时候直接拽过去用,否则老是写了小例子就扔,用 ...
- html 5 drag and drop upload file
compatible: chrome firefox ie 11 , not supported demo: http://demo.tutorialzine.com/2011/09/html5-fi ...
- UITextField监听文字输入事件
[textField addTarget:self action:@selector(textFieldDidChange:)forControlEvents:UIControlEventEditin ...
- Delphi XE5 android openurl(转)
直接上代码: unit OpenViewUrl; interface // URLEncode is performed on the URL// so you need to format it p ...
- [转载]用.NET开发的磁力搜索引擎——Btbook.net
去年10月份开始研究相关的协议与资料,中途乱七八糟的事情差点没坚持下来,寒假里修修补补上礼拜把Btbook发布了,经过社交网络的推广之后,上线第三天UV就达到了两万多,也算是对这几个月工作的一点肯定吧 ...
- WCF 在VS中,添加服务引用,地址输入http://ip/Service.svc,点击前往,提示错误,内容如下:
WCF的service端的webconfig如下: <?xml version="1.0"?> <configuration> <system.ser ...
- Akka的fault tolerant
要想容错,该怎么办? 父actor首先要获知子actor的失败状态,然后确定该怎么办, “怎么办”这回事叫做“supervisorStrategy". // Restart the st ...
- Cloud Insight 和 BearyChat 第一次合体,好紧张!
说到 ChatOps 我们可能立刻想到是 Slack(啥?没听过?哦!),但是由于国内网络和语言的问题你可能无法拥有很好的体验了.那就把目光转回国内吧,国内的话就不得不提到 BearyChat 等 C ...
- 【前端学习】【CSS选择器】
CSS选择器 CSS选择器 CSS(Cascading Style Sheets)是一项出色的技术,它使得网页的结构和表现样式完全分离.利用CSS选择器能轻松地对某个元素添加样式而不改动HTM ...