BZOJ_1391_[Ceoi2008]order_最大权闭合子图
BZOJ_1391_[Ceoi2008]order_最大权闭合子图
Description
Input
Output
Sample Input
100 2
1 30
2 20
100 2
1 40
3 80
50
80
110
Sample Output
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define N 2500
#define M 3600050
#define S (n+m+1)
#define T (n+m+2)
#define inf 100000000
int head[N],to[M],nxt[M],flow[M],cnt=1,dep[N],Q[N],l,r,sum,n,m,cur[N];
inline void add(int u,int v,int f) {
to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt; flow[cnt]=f;
to[++cnt]=u; nxt[cnt]=head[v]; head[v]=cnt; flow[cnt]=0;
}
bool bfs() {
int i;
memset(dep,0,sizeof(dep)); l=r=0;
Q[r++]=S; dep[S]=1;
while(l<r) {
int x=Q[l++];
for(i=head[x];i;i=nxt[i]) {
if(!dep[to[i]]&&flow[i]) {
dep[to[i]]=dep[x]+1;
if(to[i]==T) return 1;
Q[r++]=to[i];
}
}
}
return 0;
}
int dfs(int x,int mf) {
if(x==T) return mf;
int nf=0,i;
for(i=cur[x];i;i=nxt[i]) {
if(dep[to[i]]==dep[x]+1&&flow[i]) {
int tmp=dfs(to[i],min(mf-nf,flow[i]));
if(!tmp) dep[to[i]]=0;
nf+=tmp;
flow[i]-=tmp;
if(flow[i]) cur[x]=i;
flow[i^1]+=tmp;
if(nf==mf) break;
}
}
return nf;
}
void dinic() {
int ans=sum,f,i;
while(bfs()) {
for(i=1;i<=T;i++) cur[i]=head[i];
while(f=dfs(S,inf)) ans-=f;
}
printf("%d\n",ans);
}
int main() {
scanf("%d%d",&n,&m);
int i,x,y,z,w;
for(i=1;i<=n;i++) {
scanf("%d%d",&x,&y);
add(S,i,x);
sum+=x;
while(y--) {
scanf("%d%d",&z,&w);
add(i,z+n,w);
}
}
for(i=1;i<=m;i++) {
scanf("%d",&x);
add(i+n,T,x);
}
dinic();
}
BZOJ_1391_[Ceoi2008]order_最大权闭合子图的更多相关文章
- P4177 [CEOI2008]order(网络流)最大权闭合子图
P4177 [CEOI2008]order 如果不能租机器,这就是最大权闭合子图的题: 给定每个点的$val$,并给出限制条件:如果取点$x$,那么必须取$y_1,y_2,y_3......$,满足$ ...
- P4177 [CEOI2008]order 网络流,最小割,最大权闭合子图
题目链接 \(Click\) \(Here\) 如果没有租用机器就是一个裸的最大权闭合子图.现在有了租用机器应该怎么办呢? 单独拆点是不行的,因为会和直接买下的情况脱离关系,租借是和连边直接相关的,那 ...
- BZOJ1391/LG4177 「CEOI2008」order 最大权闭合子图
问题描述 BZOJ1391 LG4177 题解 最大权闭合子图,本质是最小割 在任务和机器中间的边之前权值设为INF,代表不可违背这条规则 本题的租借就相当于允许付出一定代价,违背某个规则,只需要把中 ...
- BZOJ1565 [NOI2009]植物大战僵尸(拓扑排序 + 最大权闭合子图)
题目 Source http://www.lydsy.com/JudgeOnline/problem.php?id=1565 Description Input Output 仅包含一个整数,表示可以 ...
- HDU 3879 Base Station(最大权闭合子图)
经典例题,好像说可以转化成maxflow(n,n+m),暂时只可以勉强理解maxflow(n+m,n+m)的做法. 题意:输入n个点,m条边的无向图.点权为负,边权为正,点权为代价,边权为获益,输出最 ...
- [BZOJ 1497][NOI 2006]最大获利(最大权闭合子图)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1497 分析: 这是在有向图中的问题,且边依赖于点,有向图中存在点.边之间的依赖关系可以 ...
- HDU4971 A simple brute force problem.(强连通分量缩点 + 最大权闭合子图)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4971 Description There's a company with several ...
- HDU5855 Less Time, More profit(最大权闭合子图)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5855 Description The city planners plan to build ...
- HDU5772 String problem(最大权闭合子图)
题目..说了很多东西 官方题解是这么说的: 首先将点分为3类 第一类:Pij 表示第i个点和第j个点组合的点,那么Pij的权值等于w[i][j]+w[j][i](表示得分) 第二类:原串中的n个点每个 ...
随机推荐
- (function(){xxx})(); 写法解释
常见格式:(function() { /* code */ })(); 解释:包围函数(function(){})的第一对括号向脚本返回未命名的函数,随后一对空括号立即执行返回的未命名函数,括号内为匿 ...
- 面向对象(this的问题一)
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content=&q ...
- 深入了解Map
联系 Java中的Map类似于OC的Dictionary,都是一个个键值对组成,一键对应一值.我在之前的文章中讲解过Set,其实在JAVA底层Set依赖的也是Map,那我们都知道,Set是单列的(只有 ...
- spring是如何管理 事务的
Spring提供的事务管理可以分为两类:编程式的和声明式的.编程式的,比较灵活,但是代码量大,存在重复的代码比较多:声明式的比编程式的更灵活方便. 1.传统使用JDBC的事务管理 以往使用JDBC ...
- Unknown entity: org.jbpm.services.task.audit.TaskEventImpl
1. use this persistence.xml - simply copy it into src/main/resources/META-INF please note the name o ...
- SQL SERVER 锁资源问题
1204: cannot obtain a LOCK resource 在sql server 锁资源的限制基本是自动优化调整.如果调整过参数,可能在系统大批量查询的时候出现以上错误,或者是 alwa ...
- 老马Repository模式原文
A system with a complex domain model often benefits from a layer, such as the one provided by Data M ...
- SQL Server 远程更新目标表数据
分享一个远程更新目标库数据的存储过程,适用于更新列名一致,主键为Int类型,可远程链接的数据库. ** 温馨提示:如需转载本文,请注明内容出处.** 本文连接:http://www.cnblogs.c ...
- href="#" 是什么意思?
<a href="#" onclick="process1()">开始你表演</a>作用:书签的另一种用法建立书签语法:<a na ...
- 【转】java中PriorityQueue优先级队列使用方法
优先级队列是不同于先进先出队列的另一种队列.每次从队列中取出的是具有最高优先权的元素. PriorityQueue是从JDK1.5开始提供的新的数据结构接口. 如果不提供Comparator的话,优先 ...