这题就是复习下网络流。

 #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define drep(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define pb push_back
#define clr(x) memset(x, 0, sizeof(x))
#define xx first
#define yy second
using namespace std;
typedef long long i64;
typedef pair<int, int> pii;
const int inf = ~0U >> ;
const i64 INF = ~0ULL >> ;
//******************************** const int maxn = , maxm = ; struct Ed {
int u, v, nx, c, w; Ed() {}
Ed(int _u, int _v, int _nx, int _c, int _w) :
u(_u), v(_v), nx(_nx), c(_c), w(_w) {}
} E[maxm << ];
int G[maxn], edtot, cur[maxn];
void addedge(int u, int v, int c, int w) {
E[edtot] = Ed(u, v, G[u], c, w);
G[u] = edtot++;
E[edtot] = Ed(v, u, G[v], , -w);
G[v] = edtot++;
} int level[maxn], s , t;
bool bfs() {
static int que[maxn]; int qh(), qt();
clr(level);
level[que[++qt] = s] = ;
while (qh != qt) {
int x = que[++qh];
for (int i = G[x]; i != -; i = E[i].nx) if (!level[E[i].v] && E[i].c) {
level[que[++qt] = E[i].v] = level[x] + ;
}
}
return !!level[t];
}
int dfs(int u, int rm) {
if (u == t) return rm;
int rm1 = rm;
for (int &i = cur[u]; i != -; i = E[i].nx) {
if (level[E[i].v] == level[u] + && E[i].c) {
int flow = dfs(E[i].v, min(rm, E[i].c));
E[i].c -= flow, E[i ^ ].c += flow;
if ((rm -= flow) == ) break;
}
}
if (rm1 == rm) level[u] = ;
return rm1 - rm;
} int dis[maxn], vis[maxn];
bool spfa() {
static int que[maxn]; int qh(), qt();
memset(dis, 0x3f, sizeof(dis));
clr(vis);
dis[que[++qt] = s] = , vis[s] = ;
while (qh != qt) {
int x = que[++qh]; vis[x] = ;
for (int i = G[x]; i != -; i = E[i].nx) {
if (E[i].c && dis[E[i].v] > dis[x] + E[i].w) {
dis[E[i].v] = dis[x] + E[i].w;
if (!vis[E[i].v]) que[++qt] = E[i].v, vis[E[i].v] = ;
}
}
}
return dis[t] != 0x3f3f3f3f;
}
int ret;
int dinic(int u, int rm) {
vis[u] = ;
if (u == t) return rm;
int rm1 = rm;
for (int i = G[u]; i != -; i = E[i].nx) {
if (dis[E[i].v] == dis[u] + E[i].w && E[i].c && !vis[E[i].v]) {
int flow = dinic(E[i].v, min(rm , E[i].c));
E[i].c -= flow, E[i ^ ].c += flow;
ret += flow * E[i].w;
if ((rm -= flow) == ) break;
}
}
if (rm1 == rm) dis[u] = ;
return rm1 - rm;
} int main() {
int n, m, K;
scanf("%d%d%d", &n, &m, &K);
memset(G, -, sizeof(G));
rep(i, , m) {
int x, y, c, w;
scanf("%d%d%d%d", &x, &y, &c, &w);
addedge(x, y, c, w);
addedge(x, y, c, );
}
s = , t = n + ; addedge(s, , 0x3f3f3f3f, ), addedge(n, t, 0x3f3f3f3f, );
int ans();
while (bfs()) memcpy(cur, G, sizeof(G)), ans += dfs(s, 0x3f3f3f3f);
printf("%d ", ans >> );
for (int i = ; i <= edtot; i += ) {
if (E[i].w == ) E[i].c += E[i ^ ].c, E[i ^ ].c = ;
else E[i].c = 0x3f3f3f3f, E[i ^ ].c = ;
if (E[i].u == s) E[i].c = (ans >> ) + K;
}
while (spfa()) clr(vis), dinic(s, 0x3f3f3f3f);
printf("%d\n", ret);
}

bzoj-1834 network 网络扩容 【网络流】的更多相关文章

  1. 【BZOJ】【1834】【ZJOI2010】Network 网络扩容

    网络流/费用流 这题……我一开始sb了. 第一问简单的最大流…… 第二问是要建费用流的图的……但是是在第一问的最大流跑完以后的残量网络上建,而不是重建…… 我们令残量网络上原有的弧的费用全部为0(因为 ...

  2. BZOJ 1834: [ZJOI2010]network 网络扩容(最大流+最小费用最大流)

    第一问直接跑最大流.然后将所有边再加一次,费用为扩容费用,容量为k,再从一个超级源点连一条容量为k,费用为0的边到原源点,从原汇点连一条同样的边到超级汇点,然  后跑最小费用最大流就OK了. ---- ...

  3. bzoj 1834: [ZJOI2010]network 网络扩容 -- 最大流+费用流

    1834: [ZJOI2010]network 网络扩容 Time Limit: 3 Sec  Memory Limit: 64 MB Description 给定一张有向图,每条边都有一个容量C和一 ...

  4. 【bzoj1834】[ZJOI2010]network 网络扩容

    1834: [ZJOI2010]network 网络扩容 Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 2701  Solved: 1368[Submit ...

  5. [BZOJ1834][ZJOI2010]network 网络扩容 最大流+费用流

    1834: [ZJOI2010]network 网络扩容 Time Limit: 3 Sec  Memory Limit: 64 MB Submit: 3330  Solved: 1739 [Subm ...

  6. bzoj1834: [ZJOI2010]network 网络扩容

    努力看了很久样例一直过不了...然后各种输出中间过程啊巴拉巴拉弄了1h,没办法了...然后突然想到啊原来的边可以用啊为什么不用...于是A了...感人肺腑 #include<cstdio> ...

  7. BZOJ1834 [ZJOI2010]network 网络扩容 【最大流,费用流】

    1834: [ZJOI2010]network 网络扩容 Time Limit: 3 Sec  Memory Limit: 64 MB Submit: 3394  Solved: 1774 [Subm ...

  8. BZOJ_1834_[ZJOI2010]network 网络扩容_费用流

    BZOJ_1834_[ZJOI2010]network 网络扩容_费用流 题意: 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用. 求:  1.在不扩容的 ...

  9. 【BZOJ1834】[ZJOI2010]network 网络扩容 最大流+最小费用流

    [BZOJ1834][ZJOI2010]network 网络扩容 Description 给定一张有向图,每条边都有一个容量C和一个扩容费用W.这里扩容费用是指将容量扩大1所需的费用.求: 1. 在不 ...

  10. BZOJ 1834: [ZJOI2010]network 网络扩容(网络流+费用流)

    一看就知道是模板题= = ,不说什么了= = PS:回去搞期末了,暑假再来刷题了 CODE: #include<cstdio> #include<iostream> #incl ...

随机推荐

  1. HDU2181:哈密顿绕行世界问题(DFS)

    哈密顿绕行世界问题 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  2. Bootstrap学习 - JavaScript插件

     模态框 <div class="modal" id="myModal" tabindex="-1" role="dialo ...

  3. 转:Emmet 学习之路 - 2 基本语法

    http://blog.csdn.net/jizhongchun/article/details/8472755 导读:Emmet的基本语法.学习步骤是:1 基本语法: 2 html命令: 3 css ...

  4. Cisco设备IOS的恢复方法 两种方法

    如果不小心把Router或者Switch的IOS删除了,特别是Flash中的IOS和ROM中的Mini IOS都没有了的话,连启动都不行的话,有什么方法恢复它呢?答案是方法不只一种,而是两种.其实是我 ...

  5. DP CF 319 div1B

    http://codeforces.com/contest/319/problem/B 题目大意: 有删除操作,每次都删除数组右边比自己小的.且紧挨着自己的数字.问最小需要删除几次. 思路: 我们定义 ...

  6. Ubuntu安装完后设置root密码

    安装完Ubuntu 14.04后默认是没有主动设置root密码的,也就无法进入根用户. 相关阅读: Ubuntu 14.04 下载.安装.配置 整理汇总 页面 http://www.linuxidc. ...

  7. StretchAnimation伸缩动画.

    原理是继承animation  然后改变他的margintop  和marginbottom  形成2个效果 ExpandTopAnimation public class ExpandTopAnim ...

  8. GridView的RowCreated与RowDataBound事件区别

    在西门子面试时,项目负责人除了道试题关于RowCreated与RowDataBound事件区别,经过google一下,得出结果: GridView的RowCreated与RowDataBound的一个 ...

  9. UITableView 性能优化

    网络图片异步加载,SDWebImage. 文字直接 drawInRect/drawAtPoint 绘制,参考 ABTableViewCell,AdvancedTableViewCells. 本地图片也 ...

  10. UIView 视图切换

    UIView之间常用视图之间切换方式 转载自:http://www.jianshu.com/p/0d53f9402c07 在平时编写代码的过程中,页面之间的跳转可以说就和MVC模式一样是开发必须的.但 ...