题目链接:https://www.luogu.org/problemnew/show/P2762

算是拍照那个题的加强下。

输入真的很毒瘤。(都这么说但好像我的过了?)

  1. #include <queue>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <algorithm>
  6. #define ll long long
  7. using namespace std;
  8. const int maxn = 1e6 + 10;
  9. const int inf = 1e9;
  10. ll n, m, s, t, deep[maxn], maxflow, w[maxn], ans;
  11. struct edge{
  12. ll next, to, flow;
  13. }e[maxn<<2];
  14. ll head[maxn], cnt = -1;
  15. queue<ll> q;
  16. void add(ll u, ll v, ll w)
  17. {
  18. e[++cnt].flow = w; e[cnt].next = head[u]; e[cnt].to = v; head[u] = cnt;
  19. e[++cnt].flow = 0; e[cnt].next = head[v]; e[cnt].to = u; head[v] = cnt;
  20. }
  21. bool bfs(ll s, ll t)
  22. {
  23. memset(deep, 0x7f, sizeof(deep));
  24. while(!q.empty()) q.pop();
  25. q.push(s); deep[s] = 0;
  26. while(!q.empty())
  27. {
  28. ll now = q.front(); q.pop();
  29. for(ll i = head[now]; i != -1; i = e[i].next)
  30. {
  31. if(deep[e[i].to] > inf && e[i].flow)
  32. {
  33. deep[e[i].to] = deep[now] + 1;
  34. q.push(e[i].to);
  35. }
  36. }
  37. }
  38. if(deep[t] < inf) return true;
  39. else return false;
  40. }
  41. ll dfs(ll now, ll t, ll limit)
  42. {
  43. if(!limit || now == t) return limit;
  44. ll flow = 0, f;
  45. for(ll i = head[now]; i != -1; i = e[i].next)
  46. {
  47. if(deep[e[i].to] == deep[now] + 1 && (f = dfs(e[i].to, t, min(e[i].flow, limit))))
  48. {
  49. flow += f;
  50. limit -= f;
  51. e[i].flow -= f;
  52. e[i^1].flow += f;
  53. if(!limit) break;
  54. }
  55. }
  56. return flow;
  57. }
  58. void Dinic(ll s, ll t)
  59. {
  60. while(bfs(s, t))
  61. maxflow += dfs(s, t, inf);
  62. }
  63. int main()
  64. {
  65. memset(head, -1, sizeof(head));
  66. scanf("%lld%lldd",&m,&n);
  67. s = 1, t = 2 + n + m;
  68. for(ll i = 1; i <= m; i++)
  69. {
  70. ll u;
  71. scanf("%lld",&w[i]);
  72. ans += w[i];
  73. while(scanf("%lld",&u))
  74. {
  75. add(i + n + 1, u + 1, inf);
  76. if(getchar() == '\n') break;
  77. }
  78. }
  79. for(ll i = 1; i <= n; i++)
  80. {
  81. ll c;
  82. scanf("%lld",&c);
  83. add(i + 1, t, c);
  84. }
  85. for(ll i = 1; i <= m; i++)
  86. {
  87. add(s, i + n + 1, w[i]);
  88. }
  89. Dinic(s, t);
  90. for(ll i = 1; i <= m; i++)
  91. if(deep[i + 1 + n] < inf) printf("%lld ",i);
  92. printf("\r\n");
  93. for(ll i = 1; i <= n; i++)
  94. if(deep[i + 1] < inf) printf("%lld ",i);
  95. printf("\r\n");
  96. printf("%lld",ans - maxflow);
  97. return 0;
  98. }

【luogu P2762 太空飞行计划问题】 题解的更多相关文章

  1. luogu P2762 太空飞行计划问题

    好像是最大权闭合图,也就是最大流最小割啦,找出最大流的路径输出,这题如何建模呢,一样的先设源点和汇点,源点向每个计划连capacity为赞助数的边,每个计划连相应装置capacity为无穷的边,每个装 ...

  2. 洛谷 P2762 太空飞行计划问题 P3410 拍照【最大权闭合子图】题解+代码

    洛谷 P2762 太空飞行计划问题 P3410 拍照[最大权闭合子图]题解+代码 最大权闭合子图 定义: 如果对于一个点集合,其中任何一个点都不能到达此集合以外的点,这就叫做闭合子图.每个点都有一个权 ...

  3. Luogu 2762 太空飞行计划 / Libre 6001 「网络流 24 题」太空飞行计划 (网络流,最大流)

    Luogu 2762 太空飞行计划 / Libre 6001 「网络流 24 题」太空飞行计划 (网络流,最大流) Description W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行 ...

  4. 网络流24题:P2762 太空飞行计划问题

    P2762 太空飞行计划问题 题目背景 题目描述 W 教授正在为国家航天中心计划一系列的太空飞行.每次太空飞行可进行一系列商业性实验而获取利润.现已确定了一个可供选择的实验集合E={E1,E2,…,E ...

  5. P2762 太空飞行计划问题(网络流24题之一)

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

  6. P2762 太空飞行计划问题 网络流

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

  7. 【Luogu】P2762太空飞行计划(最大权闭合图)

    题目链接 woc这题目的输入格式和输出格式真的恶心 首先我们就着样例讲一下闭合图 如图所示,第一层是两个实验节点,带来正收益:第二层是三个仪器节点,带来负收益:问讲道理到终点可以获得多大收益. 闭合图 ...

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

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

  9. 洛谷 - P2762 - 太空飞行计划问题 - 最小割

    https://www.luogu.org/problemnew/solution/P2762 最小割对应的点,在最后一次更新中dinic的bfs会把他的dep重置掉.所以可以根据这个性质复原最小割. ...

随机推荐

  1. Docker的基本构架

    不多说,直接上干货! Docker的基本构架 Docker基于Client-Server架构,Docker daemon是服务端,Docker client是客户端. Docker的基本架构,如下图所 ...

  2. oracle中的exists理解

    select * from EB where exists (select * from BB where Code=EB.Code) 把select 外层表EB看成是循环的,把每一个值eb.code ...

  3. c#字典排序

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. Java网站开发的一些问题以及解决(cookie消失,上传头像,js等)

    1.首先是cookie的问题,很多人都是遇到了将数据存储到cookie中并且add到response之中,但是还有返回其他页面或者刷新页面cookie消失的情况,除了设置cookie的存活时间外, 还 ...

  5. java开发中的设计模式

    http://www.cnblogs.com/maowang1991/archive/2013/04/15/3023236.html 一.设计模式的分类 总体来说设计模式分为三大类: 创建型模式,共五 ...

  6. django基本入门

    1.创建应用 2.设计模型 3.语言时区等设置 4. Templates 1.创建应用[MVT] 一个项目可以有多个应用[模块]: 这里已经创建了项目:test1 python manager.py ...

  7. windows下快速修改host文件

    windows下快速修改host文件 win+r  输入 notepad c:\Windows\System32\drivers\etc\hosts

  8. js 匹配中文字符串(也包含日文和韩文)

    <script> var str="payTypeNam门诊账户\n\t"; document.write(str.match(/[\u4E00-\u9FA5\uF90 ...

  9. 高效的jQuery代码编写技巧

    缓存变量 DOM遍历是昂贵的,所以尽量将会重用的元素缓存. // 糟糕 h = $('#element').height(); $(); // 建议 $element = $('#element'); ...

  10. 浅谈SQL Server中的事务日志(三)----在简单恢复模式下日志的角色

    简介 在简单恢复模式下,日志文件的作用仅仅是保证了SQL Server事务的ACID属性.并不承担具体的恢复数据的角色.正如”简单”这个词的字面意思一样,数据的备份和恢复仅仅是依赖于手动备份和恢复.在 ...