BZOJ 1391 [CEOI] Order - 网络流 最大流
Solution
非常简单的建边!!!
但是刚开始的代码不够体现社会主义的优越性, 于是我 ....

惨痛教训啊。。。 终于到了今天才能够体现社会主义优越性。。。
Code
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#define rd read()
#define R register
#define rep(i,a,b) for(register int i = (a); i <= (b); ++i)
#define per(i,a,b) for(register int i = (a); i >= (b); --i)
#define ll long long
using namespace std; const int N = 1e6 + 1e5, M = 4e3;
const int inf = ~0U >> ;
int n, m, head[M], tot, cur[M];
int dep[M], S, T;
int sum, ans; queue<int> q; struct edge {
int nxt, to, val;
}e[N * ]; inline int read() {
int X = , p = ; char c = getchar();
for(; c > '' || c < ''; c = getchar()) if(c == '-') p = -;
for(; c >= '' && c <= ''; c = getchar()) X = X * + c - '';
return X * p;
} inline void added(int u, int v, int val) {
e[++tot].to = v;
e[tot].val = val;
e[tot].nxt = head[u];
head[u] = tot;
} inline void add(int u, int v, int val) {
added(u, v, val); added(v, u, );
} int ch(int x) {
return ((x + ) ^ ) - ;
} int bfs() {
rep(i, S, T) dep[i] = ;
dep[S] = ;
q.push(S);
for(R int u; !q.empty();) {
u = q.front(); q.pop();
for(R int i = head[u]; i; i = e[i].nxt) {
R int nt = e[i].to;
if(!dep[nt] && e[i].val) {
dep[nt] = dep[u] + ;
q.push(nt);
}
}
}
return dep[T];
} inline int minn(int A, int B) {
return A > B ? B : A;
} int dfs(R int u, R int flow) {
if(u == T || !flow) return flow;
if(!flow) return ;
R int re = ;
for(R int i = cur[u]; i && flow; i = e[i].nxt, cur[u] = i) {
R int nt = e[i].to;
if(dep[nt] != dep[u] + || !e[i].val) continue;
R int tmp = dfs(nt, minn(flow, e[i].val));
if(!tmp) continue;
re += tmp;
flow -= tmp;
e[i].val -= tmp;
e[i ^ ].val += tmp;
if(!flow) return re;
}
return re;
} int main()
{
n = rd; m = rd;
T = n + m + ;
tot = ;
rep(i, , n) {
R int cost = rd;
add(S, i, cost);
sum += cost;
int cnt = rd;
rep(j, , cnt) {
int x = rd, v = rd;
add(i, n + x, v);
}
}
rep(i, , m) {
R int x = rd;
add(i + n, T, x);
}
for(; bfs();) {
memcpy(cur, head, sizeof(head));
ans += dfs(S, inf);
}
printf("%d\n", sum - ans);
}
BZOJ 1391 [CEOI] Order - 网络流 最大流的更多相关文章
- Bzoj 1391: [Ceoi2008]order 网络流,最大权闭合图
1391: [Ceoi2008]order Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1105 Solved: 331[Submit][Statu ...
- BZOJ 1391 [Ceoi2008]order
1391: [Ceoi2008]order Description 有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成,你可以通过购买或租用机器来完 ...
- BZOJ 1391: [Ceoi2008]order [最小割]
1391: [Ceoi2008]order Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1509 Solved: 460[Submit][Statu ...
- bzoj 1391 [Ceoi2008]order(最小割)
[题意] 有n个有偿工作选做,m个机器,完成一个工作需要若干个工序,完成每个工序需要一个机器,对于一个机器,在不同的工序有不同的租费,但买下来的费用只有一个.问最大获益. [思路] 对于工作和机器建点 ...
- POJ 1459-Power Network(网络流-最大流-ISAP)C++
Power Network 时间限制: 1 Sec 内存限制: 128 MB 题目描述 A power network consists of nodes (power stations, cons ...
- [POJ1273][USACO4.2]Drainage Ditches (网络流最大流)
题意 网络流最大流模板 思路 EK也不会超时 所以说是一个数据比较水的模板题 但是POJ有点坑,多组数据,而且题目没给 哭得我AC率直掉 代码 用的朴素Dinic #include<cstdio ...
- HDU 3081 Marriage Match II (网络流,最大流,二分,并查集)
HDU 3081 Marriage Match II (网络流,最大流,二分,并查集) Description Presumably, you all have known the question ...
- HDU1532 网络流最大流【EK算法】(模板题)
<题目链接> 题目大意: 一个农夫他家的农田每次下雨都会被淹,所以这个农夫就修建了排水系统,还聪明的给每个排水管道设置了最大流量:首先输入两个数n,m ;n为排水管道的数量,m为节点的数量 ...
- Redraw Beautiful Drawings(hdu4888)网络流+最大流
Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
随机推荐
- 导出pdf
document.getElementById("exportSiteInfoTemp").onclick = function() { var thisMinheight=$(& ...
- java.lang.IllegalAccessError: tried to access method
java.lang.IllegalAccessException: access to method denied 06-23 16:12:39.128 1253-1253/com.hbjyjt.oa ...
- maven 配置 阿里仓库
<mirror><id>nexus-aliyun</id><mirrorOf>central</mirrorOf><name>N ...
- HTTP协议(Requset、Response)
目录 http协议 http报文解析: Http请求(浏览器->服务器) HttpServletRequest对象: Http响应(服务器->浏览器) HttpServletRespons ...
- JDBC的基本概念
英文名:Java DataBase Connectivity 中文名:数据库连接 作用: java操作数据库 本质上(sun公司的程序员)定义的一套操作关系型数据库的规则也就是接口,各数据库厂商实现接 ...
- Bootstrap的aria-label和aria-labelledby
[Bootstrap的aria-label和aria-labelledby] 用于盲人阅读的属性,基本也没什么用. 参考:http://blog.csdn.net/liuyan19891230/art ...
- Linux系统缓冲区溢出
Linux系统下穿越火线-缓冲区溢出 原理:crossfire 1.9.0 版本接受入站 socket 连接时存在缓冲区溢出漏洞. 工具: 调试工具:edb: ###python在漏洞溢出方面的渗透测 ...
- 【MongoDB】关于无法连接mongo的问题
今天使用MongoDB的时候发现直接输入mongo提示连接失败 首先想到的可能是服务还没启动 当我随便打开一个cmd输入net start MongoDB 提示:net start mongodb 发 ...
- pyinstaller linux系统下打包python源文件
将python程序放在其他linux服务器中执行,通常linux服务器中默认安装python2.6,很多情况下需要升级为2.7 且要安装程序中需要的第三方模块,配置较为麻烦,所以通过在本地linux ...
- Django model 中的 class Meta 详解
Django model 中的 class Meta 详解 通过一个内嵌类 "class Meta" 给你的 model 定义元数据, 类似下面这样: class Foo(mode ...