bzoj1391 最大权闭合子图(also最小割、网络流)
一道裸的最小割的题,写一下只是练练手。
表示被卡M,RE不开心。一道裸题至于吗?
再次复习一下最大权闭合子图:
1.每一个点若为正权,与源点连一条容量为绝对值权值的边。否则连向汇点一条容量为绝对值权值的边
2.如果有选了A点才能选B点的约束条件,且违背这个约束条件有C的代价,则从A点向B点连一条容量为C的边(如果不能违背,则连一条容量为INF的边)
3.设源点出度为C,最大流的值为D。答案为C-D。
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std ; namespace DINIC { const int MAXVn = * + ;
const int MAXEn = * + ;
int Vn ; struct edge {
int p ;
int c ;
edge * nxt ;
edge * brother ;
} ; edge E [ MAXEn * ] ;
namespace E_SET { edge * T = E ; } ;
edge * V [ MAXVn ] ; int S , T ; void add_edge ( const int a , const int b , const int f ) {
using E_SET :: T ;
T -> p = b ; T -> c = f ; T -> nxt = V [ a ] ; V [ a ] = T ++ ;
T -> p = a ; T -> c = ; T -> nxt = V [ b ] ; V [ b ] = T ++ ;
V [ a ] -> brother = V [ b ] ; V [ b ] -> brother = V [ a ] ;
} edge * cur [ MAXVn ] ;
int dis [ MAXVn ] ; bool bfs ( ) {
queue < int > q ;
fill ( dis , dis + Vn , - ) ;
copy ( V , V + Vn , cur ) ;
q . push ( S ) ; dis [ S ] = ;
while ( ! q . empty () ) {
const int o = q . front () ; q . pop () ;
for ( edge * v = V [ o ] ; v != ; v = v -> nxt )
if ( v -> c != && dis [ v -> p ] == - ) {
dis [ v -> p ] = dis [ o ] + ;
q . push ( v -> p ) ;
}
}
return dis [ T ] != - ;
} int dfs ( const int o , int flow ) {
if ( o == T || flow == ) return flow ;
int f , ans = ;
for ( edge * & v = cur [ o ] ; v != ; v = v -> nxt )
if ( dis [ o ] + == dis [ v -> p ] &&
( f = dfs ( v -> p , min ( flow , v -> c ) ) ) != ) {
v -> c -= f ; v -> brother -> c += f ;
ans += f ; flow -= f ;
if ( flow == ) break ;
}
return ans ;
} int dinic ( ) {
int ans = ;
while ( bfs ( ) ) ans += dfs ( S , << ) ;
return ans ;
} } int M , N ;
int sum ; int main () { using namespace DINIC ;
scanf ( "%d%d" , & N , & M ) ;
Vn = M + N + ; //in && out && S && T
S = ;
T = ; #define WORK(a) ((a)+2)
#define MACHINE(a) ((a)+N+2) for ( int i = ; i < N ; ++ i ) {
int value_of_w , num_of_w ; scanf ( "%d%d" , & value_of_w , & num_of_w ) ;
sum += value_of_w ;
add_edge ( S , WORK(i) , value_of_w ) ;
while ( num_of_w -- ) {
int n , pay ;
scanf ( "%d%d" , & n , & pay ) ;
n -= ;
add_edge ( WORK(i) , MACHINE(n) , pay ) ;
}
}
for ( int i = ; i < M ; ++ i ) {
int pay ; scanf ( "%d" , & pay ) ;
add_edge ( MACHINE(i) , T , pay ) ;
} #undef WORK
#undef MACHINE printf ( "%d\n" , sum - dinic () ) ; return ; }
bzoj1391 最大权闭合子图(also最小割、网络流)的更多相关文章
- 【BZOJ】1497: [NOI2006]最大获利 最大权闭合子图或最小割
[题意]给定n个点,点权为pi.m条边,边权为ci.选择一个点集的收益是在[点集中的边权和]-[点集点权和],求最大获利.n<=5000,m<=50000,0<=ci,pi<= ...
- LuoguP2762 太空飞行计划问题(最大权闭合子图,最小割)
题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,Em},和进行这些实验需要使用的全部仪器的 ...
- Petya and Graph/最大权闭合子图、最小割
原题地址:https://codeforces.com/contest/1082/problem/G G. Petya and Graph time limit per test 2 seconds ...
- HDU 3917 最大权闭合图 求最小割
具体参考http://blog.csdn.net/power721/article/details/6665750 TODO //#pragma comment(linker, "/STAC ...
- Less Time, More profit 最大权闭合子图(最大流最小割)
The city planners plan to build N plants in the city which has M shops. Each shop needs products fro ...
- BZOJ 4873 [Shoi2017]寿司餐厅 | 网络流 最大权闭合子图
链接 BZOJ 4873 题解 当年的省选题--还记得蒟蒻的我Day1 20分滚粗-- 这道题是个最大权闭合子图的套路题.严重怀疑出题人就是先画好了图然后照着图编了个3000字的题面.和我喜欢的妹子当 ...
- 【POJ 2987】Firing (最小割-最大权闭合子图)
裁员 [问题描述] 在一个公司里,老板发现,手下的员工很多都不务正业,真正干事员工的没几个,于是老板决定大裁员,每开除一个人,同时要将其下属一并开除,如果该下属还有下属,照斩不误.给出每个人的贡献值和 ...
- BZOJ 1565 NOI2009 植物大战僵尸 topo+最小割(最大权闭合子图)
题目链接:https://www.luogu.org/problemnew/show/P2805(bzoj那个实在是有点小小的辣眼睛...我就把洛谷的丢出来吧...) 题意概述:给出一张有向图,这张有 ...
- 洛谷 P4174 [NOI2006]最大获利 && 洛谷 P2762 太空飞行计划问题 (最大权闭合子图 && 最小割输出任意一组方案)
https://www.luogu.org/problemnew/show/P4174 最大权闭合子图的模板 每个通讯站建一个点,点权为-Pi:每个用户建一个点,点权为Ci,分别向Ai和Bi对应的点连 ...
随机推荐
- iOS:CALayer核心动画层上绘图
在CALayer上绘图: •要在CALayer上绘图,有两种方法: 1.创建一个CALayer的子类,然后覆盖drawInContext:方法,可以使用Quartz2D API在其中进行绘图 2.设置 ...
- Linux配置自建 YUM 软件存储库
yum软件仓库的搭建方式有三种,分别是本地yum源,网络yum源,第三方软件仓库. 以下示例演示了搭建本地yum仓库的方法: 1. 删除 /etc/yum.repos.d/dvd.repo 这个仓库文 ...
- Linux SHELL脚本
在Linux系统中,虽然有各种各样的图形化接口工具,但是sell仍然是一个非常灵活的工具.Shell不仅仅是命令的收集,而且是一门非常棒的编程语言.可以通过使用shell使大量的任务自动化,shell ...
- 一些practice和总结(转载)
转自 http://boundary.cc/2013/05/java-app-server-develop/ by JOKER on 2013/05/05 最近状态不是很好,负能量堆到积爆表,静下心来 ...
- ZOJ Problem Set - 3865 Superbot (bfs)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5477 大牛博客:http://www.cnblogs.com/kylehz/p ...
- html5 getComputedStyle + resize 实现动态宽高度等比响应式页面设计
序:通常我们只能控制div的宽度 而不能控制高度,在响应式页面里 如果要这个div是正方形那么必须的用媒体查询在不同的分辨率下写死宽高度 今天突发奇想研究了个 用百分比来动态控制div的高度让其与宽度 ...
- android 启动第三方程序的代码
//启动媒体库 Intent i = new Intent(); ComponentName comp = new ComponentName("com.android.camera&q ...
- some resource favor
http://www.moxiemanager.com/getit/ : picture file manage with blur 可以和Tinymce结合使用完美实现WYSIWYG的效果 http ...
- Qt之QLabel
简述 QLabel提供了一个文本或图像的显示,没有提供用户交互功能. 一个QLabel可以包含以下任意内容类型: 内容 设置 纯文本 使用setText()设置一个QString 富文本 使用setT ...
- PHP学习笔记04——数组
<?php // 1.数组的声明,可以直接为数组元素赋值,也可以使用array函数声明数组 /* 索引数组:下标从0开始,依次递增 * 关联数组:字符串为下标 * */ //直接赋值声明数组,不 ...