【传送门:BZOJ3511


简要题意:

  给出n个点,m条边,每个点有A和B两种形态,一开始1为A,n为B

  给出VA[i]和VB[i],表示第i个点选择A和B形态的价值

  每条边给出x,y,EA,EB,EC,表示如果x和y都为A,则获得EA价值,如果都为B则获得EB价值,否则会得到EC的费用(就是负价值)

  求出最大价值


题解:

  神奇的最小割,太强了

  建图膜


参考代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
struct node
{
int x,y,c,next,other;
}a[];int len,last[];
void ins(int x,int y,int c)
{
int k1=++len,k2=++len;
a[k1].x=x;a[k1].y=y;a[k1].c=c;
a[k1].next=last[x];last[x]=k1;
a[k2].x=y;a[k2].y=x;a[k2].c=;
a[k2].next=last[y];last[y]=k2;
a[k1].other=k2;
a[k2].other=k1;
}
int h[],list[],st,ed;
bool bt_h()
{
memset(h,,sizeof(h));
h[st]=;
int head=,tail=;
list[]=st;
while(head!=tail)
{
int x=list[head];
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(h[y]==&&a[k].c>)
{
h[y]=h[x]+;
list[tail++]=y;
}
}
head++;
}
if(h[ed]==) return false;
else return true;
}
int findflow(int x,int f)
{
if(x==ed) return f;
int s=,t;
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(h[y]==(h[x]+)&&a[k].c>&&f>s)
{
t=findflow(y,min(a[k].c,f-s));
s+=t;
a[k].c-=t;a[a[k].other].c+=t;
}
}
if(s==) h[x]=;
return s;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
int sum=;st=;ed=n+*m+;
len=;memset(last,,sizeof(last));
ins(st,,);
for(int i=;i<n;i++)
{
int d;
scanf("%d",&d);sum+=d;
ins(st,i,d);
}
ins(n,ed,);
for(int i=;i<n;i++)
{
int d;
scanf("%d",&d);sum+=d;
ins(i,ed,d);
}
for(int i=;i<=m;i++)
{
int x,y,ea,eb,ec;
scanf("%d%d%d%d%d",&x,&y,&ea,&eb,&ec);sum+=ea+eb;
ins(x,y,ec);ins(y,x,ec);
ins(i+n,x,);ins(i+n,y,);
ins(x,i+n+m,);ins(y,i+n+m,);
ins(st,i+n,ea);ins(i+n+m,ed,eb);
}
while(bt_h()==true) sum-=findflow(st,);
printf("%d\n",sum);
return ;
}

BZOJ3511: 土地划分的更多相关文章

  1. BZOJ3511: 土地划分(最小割)

    Description Y国有N座城市,并且有M条双向公路将这些城市连接起来,并且任意两个城市至少有一条路径可以互达. Y国的国王去世之后,他的两个儿子A和B都想成为新的国王,但他们都想让这个国家更加 ...

  2. fzu 1015 土地划分(判断线段相交+求出交点+找规律)

    链接:http://acm.fzu.edu.cn/problem.php?pid=1015  Problem 1015 土地划分 Accept: 714    Submit: 1675Time Lim ...

  3. FOJ Problem 1015 土地划分

    Problem 1015 土地划分 Accept: 823    Submit: 1956Time Limit: 1000 mSec    Memory Limit : 32768 KB  Probl ...

  4. BZOJ 3511 土地划分

    AC通道:http://www.lydsy.com/JudgeOnline/problem.php?id=3511 题目分析: 看上去和前面的人员雇佣以及小M种田都很像. 最小割模型来求最大值,一般都 ...

  5. FZU 1015 土地划分

        Description 在Dukeswood这块土地上生活着一个富有的农庄主和他的几个孩子.在他临终时,他想把他的土地分给他的孩子.他有许多农场,每个农场都是一块矩形土地.他在农场地图上划上一 ...

  6. UVa1515 Pool construction(最小割)

    题目 Source https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. 【noip模拟赛3】拣钱

    描述 最近,Henry由于失恋(被某大牛甩掉!)心情很是郁闷.所以,他去了大牛家,寻求Michael大牛的帮助,让他尽快从失恋的痛苦中解脱出来.Michael大牛知道Henry是很爱钱的,所以他是费尽 ...

  8. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  9. (DFS)HDU_1241 Oil Deposits

    HDU_1241 Oil Deposits   Problem Description The GeoSurvComp geologic survey company is responsible f ...

随机推荐

  1. python中*号用法总结

    python 中有很多地方用到星号,有时候会想知道这个*是干嘛用的,总结如下,有不当之处,还望不吝指出,谢谢.1.乘法: 在很多时候是用作乘法的,例如: In [90]: 2*7 Out[90]: 1 ...

  2. php7 memcache和memcached.so扩展

    php7安装memcache和memcached扩展 https://github.com/websupport-sk/pecl-memcache https://github.com/php-mem ...

  3. vue-lazyload插件

    更详细的内容,请移步 使用 npm install vue-lazyload --save //注册插件 import vueLazyload from 'vue-lazyload' Vue.use( ...

  4. 《Craking the Coding interview》python实现---01

    ###题目:给定一个字符串,判断其中是否有重复字母###思路:将重复的字符放入到list中,并进行计数统计###实现:伪代码.函数.类实现###伪代码:string=s #给定的字符串list=[] ...

  5. 【codeforces 496E】Distributing Parts

    [题目链接]:http://codeforces.com/contest/496/problem/E [题意] 给你n个歌曲; 每个歌曲有一个需要声音的区间li,ri; 然后给你m个人; 每个人也有一 ...

  6. RPC架构

    RPC架构 学习了: https://www.cnblogs.com/ChrisMurphy/p/6550184.html RPC架构简介,有一个Java例子: http://blog.csdn.ne ...

  7. 移动端页面弹出对话框效果Demo

    核心思路:设置一个隐藏的(display:none;).背景偏暗的div及其子div作为对话框.当点击某处时,将此div设置为显示. 核心代码例如以下(部分js代码用于动态调整div内容的行高.这部分 ...

  8. css实现上下左右布局

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. [BZOJ3670] [NOI2014] 动物园 解题报告 (KMP)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=3670 Description 近日,园长发现动物园中好吃懒做的动物越来越多了.例如企鹅, ...

  10. BZOJ 1336&1337最小圆覆盖

    思路: http://blog.csdn.net/commonc/article/details/52291822 (照着算法步骤写--) 已知三点共圆 求圆心的时候 就设一下圆心坐标(x,y) 解个 ...