枚举建图.jpg

一开始建的图挂了,于是枚举了几种建图方式……

因为要删点,所以拆点,连接(i,i',1),对于原来图上的边(u,v),连接(u',v,inf),(v',u,inf),然后连接(s,i',inf),对于不能和1相连的点x,建边(x,t,inf)

跑dinic即可

原因的话,枚举出来就好啦 考虑1不能和x相连,把1和x分别连s和t,这样模型就转换为把st割开的最小割了

比如下图这样,原图有一条1→i→x的通路而1,x不能互相连接,所以正好是把(i,i',1)这条边割掉,说明删掉i点

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<queue>
  4. #include<cstring>
  5. using namespace std;
  6. const int N=10005,inf=1e9;
  7. int n,m,q,h[N],cnt=1,s,t,le[N];
  8. struct qwe
  9. {
  10. int ne,to,va;
  11. }e[N*100];
  12. int read()
  13. {
  14. int r=0,f=1;
  15. char p=getchar();
  16. while(p>'9'||p<'0')
  17. {
  18. if(p=='-')
  19. f=-1;
  20. p=getchar();
  21. }
  22. while(p>='0'&&p<='9')
  23. {
  24. r=r*10+p-48;
  25. p=getchar();
  26. }
  27. return r*f;
  28. }
  29. void add(int u,int v,int w)
  30. {
  31. cnt++;
  32. e[cnt].ne=h[u];
  33. e[cnt].to=v;
  34. e[cnt].va=w;
  35. h[u]=cnt;
  36. }
  37. void ins(int u,int v,int w)
  38. {
  39. add(u,v,w);
  40. add(v,u,0);
  41. }
  42. bool bfs()
  43. {
  44. queue<int>q;
  45. memset(le,0,sizeof(le));
  46. le[s]=1,q.push(s);
  47. while(!q.empty())
  48. {
  49. int u=q.front();
  50. q.pop();
  51. for(int i=h[u];i;i=e[i].ne)
  52. if(!le[e[i].to]&&e[i].va>0)
  53. {
  54. le[e[i].to]=le[u]+1;
  55. q.push(e[i].to);
  56. }
  57. }
  58. return le[t];
  59. }
  60. int dfs(int u,int f)
  61. {
  62. if(u==t||!f)
  63. return f;
  64. int us=0;
  65. for(int i=h[u];i&&us<f;i=e[i].ne)
  66. if(le[e[i].to]==le[u]+1&&e[i].va>0)
  67. {
  68. int t=dfs(e[i].to,min(e[i].va,f-us));
  69. e[i].va-=t;
  70. e[i^1].va+=t;
  71. us+=t;
  72. }
  73. if(!us)
  74. le[u]=0;
  75. return us;
  76. }
  77. int dinic()
  78. {
  79. int re=0;
  80. while(bfs())
  81. re+=dfs(s,inf);
  82. return re;
  83. }
  84. int main()
  85. {
  86. n=read(),m=read(),q=read();
  87. s=0,t=2*n+1;
  88. for(int i=1;i<=m;i++)
  89. {
  90. int x=read(),y=read();
  91. ins(x+n,y,inf),ins(y+n,x,inf);
  92. }
  93. ins(s,1+n,inf);//ins(1,1+n,inf);
  94. for(int i=1;i<=n;i++)
  95. ins(i,i+n,1);
  96. for(int i=1;i<=q;i++)
  97. {
  98. int x=read();
  99. ins(x,t,inf);
  100. }
  101. printf("%d\n",dinic());
  102. return 0;
  103. }

bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害【最小割】的更多相关文章

  1. bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害

    1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害 Description Farmer John的农场里有P个牧场,有C条无向道路连接着他们,第i条道路连接着 ...

  2. 【BZOJ】1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害

    [题意]给定无向图,现在可能有一些点已经被删除,只给出信息是c个点未被删除且不能到达结点1,求最少的删除点个数. [算法]最小割 [题解]本题和1的区别是:1求的是最少的不能到达1的结点数,那么就把损 ...

  3. 【bzoj1585】[Usaco2009 Mar]Earthquake Damage 2 地震伤害 网络流最小割

    题目描述 Farmer John的农场里有P个牧场,有C条无向道路连接着他们,第i条道路连接着两个牧场Ai和Bi,注意可能有很多条道路连接着相同的Ai和Bi,并且Ai有可能和Bi相等.Farmer J ...

  4. BZOJ1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害

    n<=3000个点m<=20000条无向边的图,有p<=n个出发点,每个出发点都不可拆,现拆一些点使每个出发点都不能到达点1,求最小点数. 简单的最小割.每个点拆成两个x和y,无向边 ...

  5. BZOJ 1585: Earthquake Damage 2 地震伤害 网络流 + 最小割

    Description Farmer John的农场里有P个牧场,有C条无向道路连接着他们,第i条道路连接着两个牧场Ai和Bi,注意可能有很多条道路连接着相同的Ai和Bi,并且Ai有可能和Bi相等.F ...

  6. [Usaco2009 MAR] Earthquake Damage 2

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1585 [算法] 一个最小割的经典模型 , 详见代码 时间复杂度 : O(dinic( ...

  7. DP经典 BZOJ 1584: [Usaco2009 Mar]Cleaning Up 打扫卫生

    BZOJ 1584: [Usaco2009 Mar]Cleaning Up 打扫卫生 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 419  Solve ...

  8. bzoj 3399: [Usaco2009 Mar]Sand Castle城堡

    3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec  Memory Limit: 128 MB Description 约翰用沙子建了一座城堡.正 ...

  9. BZOJ 3401: [Usaco2009 Mar]Look Up 仰望( 单调栈 )

    n <= 105 , 其实是10 ^ 5 ....坑...我一开始写了个模拟结果就 RE 了.. 发现这个后写了个单调栈就 A 了... ---------------------------- ...

随机推荐

  1. 对于BFC(block format context)理解

    目录 前言 Box: CSS布局的基本单位&盒模型 什么是BFC?(Block formatting contexts) 元素与盒 正常流 块级与行内级 产生垂直外边距合并的必备条件 前言 什 ...

  2. Discuz 论坛修改admin账户密码

    打开Navicat for MySQL 找到数据表 pre_ucenter_members 把密码修改为123456789 password:047099adb883dc19616dae0ef2adc ...

  3. 【(待重做)树状数组+dp+离散化】Counting Sequences

    https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/G [题意] 给定一个数组a,问这个数组有多少个子序列,满足子序列中任意两个相邻数 ...

  4. Flask(4):wtforms组件 & 数据库连接池 DBUtils

    wtforms 组件的作用: --- 生成 HTML 标签 --- form 表单验证 示例代码: app.py from flask import Flask, render_template, r ...

  5. Mysql Replace语句的使用

    Mysql Replace语句的语法: REPLACE [LOW_PRIORITY | DELAYED] [INTO] tbl_name [(col_name,...)] VALUES ({expr ...

  6. topshelf生成Windows服务

    一.  概述 Visual C# 工程中选取 Windows 服务(Windows Service)选项,可以创建Windows服务程序,这种开发方式对于开发来说不方便调试,今天介绍另外一种生成Win ...

  7. [NOIP2004] 普及组

    不高兴的津津 纯模拟 #include<cmath> #include<cstdio> #include<iostream> using namespace std ...

  8. Multiprocessing system employing pending tags to maintain cache coherence

    A pending tag system and method to maintain data coherence in a processing node during pending trans ...

  9. Linux下汇编语言学习笔记44 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  10. POJ 3370 Halloween treats(抽屉原理)

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 6631   Accepted: 2448 ...