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个点每个 ...
随机推荐
- cookie的增删改查函数
function setCookie(name,value,expires,path,domain){ //设置过期时间 var oDate = new Date(); oDate.setDate(o ...
- eclipse中英文(等各国语言)版本转换发放
eclipse界面语言的切换方法 1.该方法只支持安装过中文包的eclipse(其实中文包中几乎包含了全世界所有的语言,只是调用了其中的中文简体而已) 2.在桌面的快捷方式中目标的地址后面加上参数-n ...
- HTML 5核心内容
demo飞象 HTML 5 系列文章索引:http://www.cnblogs.com/webabcd/archive/2012/05/27/2520567.html demo飞象HTML 5 (11 ...
- unity零基础开始学习做游戏(二)让你的对象动起来
-------小基原创,转载请给我一个面子 小基认为电子游戏与电影最重要的区别就是交互,如果电子游戏没有让你输入的交互功能的话,全程都"只可远观,而不可鼓捣"的话,你可能是在看视频 ...
- Mybatis 系列5
上篇系列4中 为大家介绍了mybatis中别名的使用,以及其源码.本篇将为大家介绍TypeHandler, 并简单分析其源码. Mybatis中的TypeHandler是什么? 无论是 MyBatis ...
- 基于Python的数据分析(3):文件和时间
在接下来的章节中,我会重点介绍一下我自己写的基于之前做python数据分析的打包接口文件common_lib,可以认为是专用于python的第三方支持库.common_lib目前包括文件操作.时间操作 ...
- python爬虫入门(七)Scrapy框架之Spider类
Spider类 Spider类定义了如何爬取某个(或某些)网站.包括了爬取的动作(例如:是否跟进链接)以及如何从网页的内容中提取结构化数据(爬取item). 换句话说,Spider就是您定义爬取的动作 ...
- python_重写数组
class MyArray: '''All the elements in this array must be numbers''' def __IsNumber(self,n): if not i ...
- linux几种时间函数总结
一.linux时间函数总结 最近的工作中用到的时间函数比较频繁,今天抽时间总结一下,在linux下,常用的获取时间的函数有如下几个: asctime, ctime, gmtime, localti ...
- Linux kernel的中断子系统之(七):GIC代码分析
返回目录:<ARM-Linux中断系统>. 总结: 原文地址:<linux kernel的中断子系统之(七):GIC代码分析> 参考代码:http://elixir.free- ...