一道裸的最小割的题,写一下只是练练手。

表示被卡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最小割、网络流)的更多相关文章

  1. 【BZOJ】1497: [NOI2006]最大获利 最大权闭合子图或最小割

    [题意]给定n个点,点权为pi.m条边,边权为ci.选择一个点集的收益是在[点集中的边权和]-[点集点权和],求最大获利.n<=5000,m<=50000,0<=ci,pi<= ...

  2. LuoguP2762 太空飞行计划问题(最大权闭合子图,最小割)

    题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,Em},和进行这些实验需要使用的全部仪器的 ...

  3. Petya and Graph/最大权闭合子图、最小割

    原题地址:https://codeforces.com/contest/1082/problem/G G. Petya and Graph time limit per test 2 seconds ...

  4. HDU 3917 最大权闭合图 求最小割

    具体参考http://blog.csdn.net/power721/article/details/6665750 TODO //#pragma comment(linker, "/STAC ...

  5. Less Time, More profit 最大权闭合子图(最大流最小割)

    The city planners plan to build N plants in the city which has M shops. Each shop needs products fro ...

  6. BZOJ 4873 [Shoi2017]寿司餐厅 | 网络流 最大权闭合子图

    链接 BZOJ 4873 题解 当年的省选题--还记得蒟蒻的我Day1 20分滚粗-- 这道题是个最大权闭合子图的套路题.严重怀疑出题人就是先画好了图然后照着图编了个3000字的题面.和我喜欢的妹子当 ...

  7. 【POJ 2987】Firing (最小割-最大权闭合子图)

    裁员 [问题描述] 在一个公司里,老板发现,手下的员工很多都不务正业,真正干事员工的没几个,于是老板决定大裁员,每开除一个人,同时要将其下属一并开除,如果该下属还有下属,照斩不误.给出每个人的贡献值和 ...

  8. BZOJ 1565 NOI2009 植物大战僵尸 topo+最小割(最大权闭合子图)

    题目链接:https://www.luogu.org/problemnew/show/P2805(bzoj那个实在是有点小小的辣眼睛...我就把洛谷的丢出来吧...) 题意概述:给出一张有向图,这张有 ...

  9. 洛谷 P4174 [NOI2006]最大获利 && 洛谷 P2762 太空飞行计划问题 (最大权闭合子图 && 最小割输出任意一组方案)

    https://www.luogu.org/problemnew/show/P4174 最大权闭合子图的模板 每个通讯站建一个点,点权为-Pi:每个用户建一个点,点权为Ci,分别向Ai和Bi对应的点连 ...

随机推荐

  1. 构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统

    开篇:从50开始系统已经由MVC4+EF5+UNITY2.X+Quartz 2.0+easyui 1.3.4无缝接入 MVC5+EF6+Unity4.x+Quartz 2.3 +easyui 1.4. ...

  2. ExtJs combobox支持模糊匹配

    其实很简单,我们只需要在创建下拉框时,给下拉框添加一个监听事件,代码如下:   //以下监听事件用于对下拉项进行模糊匹配                     ,listeners:{       ...

  3. [转载]TexturePacker 如何使用自带的加密功能及在cocos2dx中的使用

    在cocos2dx中使用纹理图集是非常节省资源的,在这里推荐 TexturePacker,而且 TexturePacker工具的加密接口也非常的好用,下面就来介绍一下... TexturePacker ...

  4. 同一Session中的aspx页面的并发限制

    项目中客户端采用WebBrowser展示aspx页面,用户有可能打开带多个带WebBrowser的winform窗体.此时,如果其中一个的WebBrowser的aspx页面响应较长的话,其他窗体中的W ...

  5. Android端通过HttpURLConnection上传文件到服务器

    Android端通过HttpURLConnection上传文件到服务器 一:实现原理 最近在做Android客户端的应用开发,涉及到要把图片上传到后台服务器中,自己选择了做Spring3 MVC HT ...

  6. Android内存管理(4)*官方教程 含「高效内存的16条策略」 Managing Your App's Memory

    Managing Your App's Memory In this document How Android Manages Memory Sharing Memory Allocating and ...

  7. C# 时间戳和时间的相互转换

    时间戳定义为从格林威治时间 1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数. C#格式时间转时间戳Timestamp private in ...

  8. 无锁编程(四) - CAS与ABA问题

    CAS 一般采用原子级的read-modify-write原语来实现Lock-Free算法,其中LL和SC是Lock-Free理论研究领域的理想原语,但实现这些原语需要CPU指令的支持,非常遗憾的是目 ...

  9. Android uiautomator gradle build system

    This will guide you through the steps to write your first uiautomator test using gradle as it build ...

  10. 【笨嘴拙舌WINDOWS】Dj,oh!nonono,It is about DC

    “DC: Device content 设备描述表.通常指显示器,或者打印机设备的描述” 如果你不是从事打印机方面的编程,那么就可以将DC简单的理解为显示器的属性表.WINDOWS将内存里面的东西通过 ...