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

表示被卡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. 配置Linux系统网卡连接网络

    本实验需要两台虚拟机来完成,环境如下: 主机名称 操作系统 ip地址 本地主机 RHEL7_64 192.168.157.134 -> 192.168.129.127 远程主机 CentOS 6 ...

  2. PowerDesiger 15逆向生成工程E-R图及导出word表格

    应用环境:win8(64位)+oracle10g(32位)服务端+PowerDesigner15 需求:oracle数据库中的表结构是web工程框架hibernate 自动生成,现需要将数据库中已有的 ...

  3. c# ffmpeg视频转换

    c#  ffmpeg视频转换 什么是ffmpeg,它有什么作用呢,怎么可以使用它呢,带着问题去找答案吧!先参考百度百科把,我觉得它很强大无奇不有,为了方便大家我就把链接提供了! http://baik ...

  4. 将SQL Azure数据库备份到本地SQL Server 2012

    整个备份过程可以分为如下两大步骤进行: 一.通过“Export Data-tier Application”先将目标SQL Azure的数据库备份到本地,详细步骤如下: 1.启动SQL Server ...

  5. Eclipse 下如何删除一个项目的 SVN 信息

    选中项目,右键 - Team - 断开连接 出现如下对话框,根据需要,选择 “删除”或者“不删除”,点击 Yes 即可

  6. R.id.layout等不能识别:cannot be resolved or is not a field

    Do not modify the R class. The error means there's something syntactically wrong with your XML layou ...

  7. OracleApps 什么是Back to Back Order?

    什么是Back to Back Order? 简单的说,B2B是我们从供应商那拿货,然后收到货后,再发运给客户.. B2B Flow B2B的例子 1.Item的定义 Item Should be c ...

  8. CreateCompatibleDC与CreateCompatibleBitmap

    函数功能:该函数创建一个与指定设备兼容的内存设备上下文环境(DC). 函数原型:HDC CreateCompatibleDC(HDC hdc): 参数: hdc:现有设备上下文环境的句柄,如果该句柄为 ...

  9. minimum-number-of-arrows-to-burst-balloons(还挺好)

    https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/ 与会议室排期问题,很相似. package com. ...

  10. Redis的过滤器(SCAN)功能

    在写另一篇文章( link )的时候,涉及到过滤器(filter)功能.以前没有接触过,整理如下. 主要参考这两篇: http://blog.csdn.net/u011510825/article/d ...