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$: 需 ...
随机推荐
- 字符设备驱动中cdev与inode、file_operations的关系
一.cdev与inode 二.cdev与file_operations
- Hadoop学习---安装部署
hadoop框架 Hadoop使用主/从(Master/Slave)架构,主要角色有NameNode,DataNode,secondary NameNode,JobTracker,TaskTracke ...
- net use命令详细解释
1)建立空连接: net use \\IP\ipc$ "" /user:"" (一定要注意:这一行命令中包含了3个空格) 2)建立非空连接: net use \ ...
- python学习笔记16(错误、异常)
一.什么是错误,什么是异常 错误是指在执行代码过程中发生的事件,它中断或干扰代码的正常流程并创建异常对象.当错误中断流程时,该程序将尝试寻找异常处理程序(一段告诉程序如何对错误做出响应的代码),以帮助 ...
- Visual Studio 中TODO List的使用
http://msdn.microsoft.com/en-us/library/txtwdysk.aspx 工欲善其事,必先利其器 When the Task List is open, you ca ...
- 如何安装Favicon
如何安装Favicon favicon.ico图像放在根目录下(也可以是其他目录)在页面源文件的<head></head>标签之间插入 <link rel="s ...
- @Repository、@Service、@Controller 和 @Component(转)
鸣谢:http://blog.csdn.net/ye1992/article/details/19971467 @Repository.@Service.@Controller 和 @Componen ...
- PAT-乙级-1002. 写出这个数 (20)
1002. 写出这个数 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 读入一个自然数n,计算其各位数字 ...
- C++ static、const和static const 以及它们的初始化
转自C++ static.const和static const 以及它们的初始化 const定义的常量在超出其作用域之后其空间会被释放,而static定义的静态常量在函数执行后不会释放其存储空间. s ...
- C++ 嵌套类使用(二)
C++嵌套类 1. 嵌套类的名字只在外围类可见. 2. 类的私有成员只有类的成员和友元可以访问,因此外围类不可以访问嵌套类的私有成员.嵌套类可以访问外围类的成员(通过对象.指针或者引用). 3 ...