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$: 需 ...
随机推荐
- HTTP的长短连接、长短轮询的区别(转载)
引言 最近刚到公司不到一个月,正处于熟悉项目和源码的阶段,因此最近经常会看一些源码.在研究一个项目的时候,源码里面用到了HTTP的长轮询.由于之前没太接触过,因此LZ便趁着这个机会,好好了解了一下HT ...
- Python for 循环 失效
昨天发现一个负责处理观察者模式的基类工作失败,默认的N个观察者负责处理 发送的一些东西, 其中提供一个内置接口移除观察者: def removeObserver(self, observer): if ...
- Thinkphp3.2.2的上传问题
学习了Thinkphp3.2.2的上传,报出了FILE: F:\development\yxk\Cord\Library\Think\Upload.class.php LINE: 257错误 这应该是 ...
- mac使用wget下载网站(仿站)
wget -c -r -np -k -L -p http://www.xxxx.com 参考 wget的安装 http://blog.csdn.net/ssihc0/article/details/7 ...
- python logging 日志轮转文件不删除问题
前言 最近在维护项目的python项目代码,项目使用了 python 的日志模块 logging, 设定了保存的日志数目, 不过没有生效,还要通过contab定时清理数据. 分析 项目使用了 logg ...
- hdu 4707 Pet(DFS水过)
http://acm.hdu.edu.cn/showproblem.php?pid=4707 [题目大意]: Lin Ji 的宠物鼠丢了,在校园里寻找,已知Lin Ji 在0的位置,输入N D,N表示 ...
- wordpress换域名后无法登陆的解决方案
第一步:登录到你的数据库管理页面,找到wp_options表: 第二步:将表中的siteurl和home字段的值修改为当前的新域名,siteurl值的修改和home值的修改同理.如下图:
- PAT-乙级-1008. 数组元素循环右移问题 (20)
1008. 数组元素循环右移问题 (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 一个数组A中存有N(N>0)个整数,在不允 ...
- uva 11143
#include<cstdio> #include<cstring> #include<algorithm> #define maxn 5100 #include& ...
- hdu 1213
简单并查集 #include <cstdio> #include <cstring> #define maxn 30005 int fa[maxn],ans[maxn],n,m ...