【传送门: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的费用(就是负价值)

  求出最大价值


题解:

  神奇的最小割,太强了

  建图膜


参考代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<algorithm>
  5. #include<cmath>
  6. using namespace std;
  7. struct node
  8. {
  9. int x,y,c,next,other;
  10. }a[];int len,last[];
  11. void ins(int x,int y,int c)
  12. {
  13. int k1=++len,k2=++len;
  14. a[k1].x=x;a[k1].y=y;a[k1].c=c;
  15. a[k1].next=last[x];last[x]=k1;
  16. a[k2].x=y;a[k2].y=x;a[k2].c=;
  17. a[k2].next=last[y];last[y]=k2;
  18. a[k1].other=k2;
  19. a[k2].other=k1;
  20. }
  21. int h[],list[],st,ed;
  22. bool bt_h()
  23. {
  24. memset(h,,sizeof(h));
  25. h[st]=;
  26. int head=,tail=;
  27. list[]=st;
  28. while(head!=tail)
  29. {
  30. int x=list[head];
  31. for(int k=last[x];k;k=a[k].next)
  32. {
  33. int y=a[k].y;
  34. if(h[y]==&&a[k].c>)
  35. {
  36. h[y]=h[x]+;
  37. list[tail++]=y;
  38. }
  39. }
  40. head++;
  41. }
  42. if(h[ed]==) return false;
  43. else return true;
  44. }
  45. int findflow(int x,int f)
  46. {
  47. if(x==ed) return f;
  48. int s=,t;
  49. for(int k=last[x];k;k=a[k].next)
  50. {
  51. int y=a[k].y;
  52. if(h[y]==(h[x]+)&&a[k].c>&&f>s)
  53. {
  54. t=findflow(y,min(a[k].c,f-s));
  55. s+=t;
  56. a[k].c-=t;a[a[k].other].c+=t;
  57. }
  58. }
  59. if(s==) h[x]=;
  60. return s;
  61. }
  62. int main()
  63. {
  64. int n,m;
  65. scanf("%d%d",&n,&m);
  66. int sum=;st=;ed=n+*m+;
  67. len=;memset(last,,sizeof(last));
  68. ins(st,,);
  69. for(int i=;i<n;i++)
  70. {
  71. int d;
  72. scanf("%d",&d);sum+=d;
  73. ins(st,i,d);
  74. }
  75. ins(n,ed,);
  76. for(int i=;i<n;i++)
  77. {
  78. int d;
  79. scanf("%d",&d);sum+=d;
  80. ins(i,ed,d);
  81. }
  82. for(int i=;i<=m;i++)
  83. {
  84. int x,y,ea,eb,ec;
  85. scanf("%d%d%d%d%d",&x,&y,&ea,&eb,&ec);sum+=ea+eb;
  86. ins(x,y,ec);ins(y,x,ec);
  87. ins(i+n,x,);ins(i+n,y,);
  88. ins(x,i+n+m,);ins(y,i+n+m,);
  89. ins(st,i+n,ea);ins(i+n+m,ed,eb);
  90. }
  91. while(bt_h()==true) sum-=findflow(st,);
  92. printf("%d\n",sum);
  93. return ;
  94. }

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. SASS 使用(vs code)

    二.在vs code中编译sass 1.在拓展商店里搜索“easy sass”,并安装,安装成功后点重新加载. 2.接下来进行配置: 在 vs code 菜单栏依次点击“文件 首选项 设置”,打开 s ...

  2. element-ui的table表格控件表头与内容列不对齐问题

    原文链接:点我 element-ui的table表格控件表头与内容列不对齐问题 解决方法:将以下样式代码添加到index.html.或app.vue中(必须是入口文件,起全局作用!)body .el- ...

  3. 平凡主丛上的Yang-Mills理论

    本文是复旦大学由丁青教授的暑期课程“Yang-Mills理论的几何及其应用”所作笔记,会有少许修正. 所需基础: 多元微积分学 微分方程(常微分方程,数学物理方程) 曲线曲面论(初等微分几何) 以下是 ...

  4. c++ string类的完整实现!!!

    本文实现了c++ STL中的basic_string模板类,当然.通过typedef也就实现了string类和wstring类.限于篇幅,实现代码中用到了标准库的char_traits模板类,本人自己 ...

  5. Android面试题目整理与解说(一)

    这一篇文章专门整理一下研究过的Android面试题,内容会随着学习不断的添加,假设答案有错误,希望大家能够指正 1.简述Activity的生命周期 当Activity開始启动的时候,首先调用onCre ...

  6. android 反编译和代码解读

    二 错误代码还原规则 if…else 语句: 反编译代码 if (paramBoolean) paramTextView.setTextColor(-16727809); while (true) { ...

  7. matplotlib 可视化 —— 绘制常见图形

    0. 饼状图 plt.pie():Python数据可视化:饼状图 1. 三角形 描点连线,起点和终点相同 triangle1 = ((0, sqrt(3)/2), (1, 3*sqrt(3)/2), ...

  8. django 笔记12 session

    第一步写好函数,然后生成数据库session表 python manage.py makemigrations python manage.py migrate session原理: .Session ...

  9. ThinkPhp5-PHPExcel导出数据

    PHP-Excel 标签(空格分隔): php 类库下载地址:https://codeload.github.com/PHPOffice/PHPExcel/zip/1.8 php导出excel表格数据 ...

  10. 3.bind与仿函数以及普通函数

    #include <iostream> #include <string> #include <vector> #include <algorithm> ...