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对应的点连 ...
随机推荐
- springboot源码解析 - 构建SpringApplication
1 package com.microservice.framework; 2 3 import org.springframework.boot.SpringApplication; 4 impor ...
- ubuntu启动eclipse时出错cannot open display
由于要学习hadoop,就在ubuntu下创建了一个hadoop用户,但是eclipse是在naomi用户下装的,在root和naomi用户下都能正常启动,但是一旦切换到hadoop用户,试着启动ec ...
- 巧用cssText属性批量操作样式
给一个HTML元素设置css属性,如 1 2 3 4 var head= document.getElementById("head"); head.style.width = & ...
- 每天一个小算法(Shell Sort2)
希尔排序: 伪代码: input: an array a of length n with array elements numbered 0 to n − 1 inc ← round(n/2) wh ...
- BZOJ 2006 超级钢琴(划分树+优先队列)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2006 题意: 给出一个数列A,L,R,构造出一个新的集合,集合中的数字为A中任意连续t( ...
- git使用ssh协议,生成公钥和私钥,并指定私钥
http://superuser.com/questions/232373/how-to-tell-git-which-private-key-to-use In ~/.ssh/config, add ...
- Sales Order Flow Statuses
OE_ORDER_LINES_ALL.flow_status_code column values execute the below query to see the values. SELECT ...
- JSON 之 SuperObject(6): 方法
SuperObject 的 JSON 对象中还可以包含 "方法", 这太有意思了; 其方法的格式是: procedure Method(const This, Params: IS ...
- cocos2d-x 获取图片的某像素点的RGBA颜色 -转
cocos2d-x 获取图片的某像素点的RGBA颜色 原文:http://www.cnblogs.com/jaoye/archive/2013/02/19/2916501.html 没做过 太多的图 ...
- how bootstrap fit into our website design?
在web相关技术中,HTML代表了content,structure, CSS则负责styling,决定内容是如何展示的,javascript则主要负责interactive, behaviour. ...