题意:懒得打了。LUCKY CAT 里有 http://163.32.78.26/homework/q10330.htm

第一个网络流题目。每个节点都有一个容量值。需要拆点。拆成i - > i + N  边权为容量值

另外注意B个点 连接方式:s - 集合B

D个点 链接方式 集合D + N -> t汇点

其他看处理就好

  1. #include <map>
  2. #include <set>
  3. #include <list>
  4. #include <cmath>
  5. #include <ctime>
  6. #include <deque>
  7. #include <stack>
  8. #include <queue>
  9. #include <cctype>
  10. #include <cstdio>
  11. #include <string>
  12. #include <vector>
  13. #include <climits>
  14. #include <cstdlib>
  15. #include <cstring>
  16. #include <iostream>
  17. #include <algorithm>
  18. #define LL long long
  19. #define PI 3.1415926535897932626
  20. using namespace std;
  21. int gcd(int a, int b) {return a % b == ? b : gcd(b, a % b);}
  22. #define MAXN 250
  23. const int INF = 0x3f3f3f3f ;
  24. int flow[MAXN][MAXN],c[MAXN][MAXN];
  25. int p[MAXN];
  26. int N,M,B,D,src,tag;
  27. void read()
  28. {
  29. memset(c,,sizeof(c));
  30. src = ; tag = * N + ;
  31. for (int i = ; i <= N; i++)
  32. {
  33. int tmp;
  34. scanf("%d",&tmp);
  35. c[i][i + N] = tmp;
  36. }
  37. scanf("%d",&M);
  38. for (int i = ; i <= M; i++)
  39. {
  40. int u,v,w;
  41. scanf("%d%d%d",&u,&v,&w);
  42. c[u + N][v] = w;
  43. }
  44. scanf("%d%d",&B,&D);
  45. for (int i = ; i <= B; i++)
  46. {
  47. int tmp;
  48. scanf("%d",&tmp);
  49. c[][tmp] = INF;
  50. }
  51. for (int i = ; i <= D; i++)
  52. {
  53. int tmp;
  54. scanf("%d",&tmp);
  55. c[tmp + N][tag] = INF;
  56. }
  57. }
  58. int Edmonds_karp(int src,int tag)
  59. {
  60. memset(flow,,sizeof(flow));
  61. int ans = ;
  62. queue<int>q;
  63. while (!q.empty()) q.pop();
  64. int a[MAXN];
  65. while (true)
  66. {
  67. memset(a,,sizeof(a));
  68. a[src] = INF;
  69. q.push(src);
  70. while (!q.empty())
  71. {
  72. int u = q.front(); q.pop();
  73. for (int v = ; v <= tag; v++)
  74. if (!a[v] && c[u][v] > flow[u][v])
  75. {
  76. p[v] = u;
  77. q.push(v);
  78. a[v] = min(a[u],c[u][v] - flow[u][v]);
  79. }
  80. }
  81. if (a[tag] == ) break;
  82. for (int u = tag; u != src; u = p[u])
  83. {
  84. flow[p[u]][u] += a[tag];
  85. flow[u][p[u]] -= a[tag];
  86. }
  87. ans += a[tag];
  88. }
  89. return ans;
  90. }
  91. int main()
  92. {
  93. //freopen("sample.txt","r",stdin);
  94. while (scanf("%d",&N)!=EOF)
  95. {
  96. read();
  97. printf("%d\n",Edmonds_karp(src,tag));
  98. }
  99. return ;
  100. }

UVA 10330 Power Transmission的更多相关文章

  1. uva 10330 - Power Transmission(网络流)

    uva 10330 - Power Transmission 题目大意:最大流问题. 解题思路:増广路算法. #include <stdio.h> #include <string. ...

  2. UVa 10330 - Power Transmission(最大流--拆点)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. UVa 10330 Power Transmission / 最大流

    最大流 这题有很多起点和终点 在取2个点(0和n+1) 作为唯一的起点和终点 此外每个点也有容量限制 建图时每条边上的容量为这条边和2个端的容量的最小值 然后EK就行 #include <cst ...

  4. light oj 1155 - Power Transmission【拆点网络流】

    1155 - Power Transmission   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  5. UVA 11149 - Power of Matrix(矩阵乘法)

    UVA 11149 - Power of Matrix 题目链接 题意:给定一个n*n的矩阵A和k,求∑kiAi 思路:利用倍增去搞.∑kiAi=(1+Ak/2)∑k/2iAi,不断二分就可以 代码: ...

  6. C2. Power Transmission (Hard Edition)(线段相交)

    This problem is same as the previous one, but has larger constraints. It was a Sunday morning when t ...

  7. C2. Power Transmission (Hard Edition) 解析(思維、幾何)

    Codeforce 1163 C2. Power Transmission (Hard Edition) 解析(思維.幾何) 今天我們來看看CF1163C2 題目連結 題目 給一堆點,每兩個點會造成一 ...

  8. UVA 11149.Power of Matrix-矩阵快速幂倍增

    Power of Matrix UVA - 11149       代码: #include <cstdio> #include <cstring> #include < ...

  9. UVa 11149 Power of Matrix(倍增法、矩阵快速幂)

    题目链接: 传送门 Power of Matrix Time Limit: 3000MS      Description 给一个n阶方阵,求A1+A2+A3+......Ak. 思路 A1+A2+. ...

随机推荐

  1. poj 2674 线性世界 弹性碰撞

    弹性碰撞的题目一般都是指碰到就会掉转方向的一类题目,这里我们可以忽略掉头,仅仅看成擦肩而过,交换名字等等 题意:一条线上N只蚂蚁,每只蚂蚁速度固定,方向和坐标不同,碰头后掉头,求最后掉下去那只蚂蚁的名 ...

  2. Servlet HttpRequest 中【getAttribute】和【getParameter】的区别

    1.获取的值不同 getAttribute表示从request范围取得设置的属性,必须要通过setAttribute设置属性,才能通过getAttribute取得.设置和取得的值都是Object类型. ...

  3. Personal Collection

    1.常用网站 序号 网址 标题 1 https://www.oschina.net/ 开源软件 2 http://tool.oschina.net/ 开发常用工具网站 3 https://docs.o ...

  4. C# WinForms跨线程更新 UI

    与在Android中一样, 子线程中更新UI被认为是线程不安全的, 会抛出异常. 子线程返回UI线程中更新UI的一个方法为: 1, 捕获应用的UI线程的上下文; 2, 定义线程任务; 3, 定义线程任 ...

  5. Dapper基础增删查改、事务和存储过程

    1.前言 Dapper是一个轻量级的orm框架,上手也非常的简单,它可以实体映射,所以先准备实体如下: public class Couser { public int id { get; set; ...

  6. PaaS服务之路漫谈(一)

    此文已由作者尧飘海授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. PaaS服务之路漫谈(一) 1983年,SUN公司提出的网络即计算的理念:2006年亚马逊(Amazon)推 ...

  7. ptmalloc,tcmalloc和jemalloc内存分配策略研究 ? I'm OWen..

    转摘于http://www.360doc.com/content/13/0915/09/8363527_314549949.shtml 最近看了glibc的ptmaoolc,Goolge的tcmall ...

  8. Python爬虫教程

    Python爬虫(1):基本原理 Python爬虫(2):Requests的基本用法 Python爬虫(3):Requests的高级用法 Python爬虫(4):Beautiful Soup的常用方法 ...

  9. install ironic-inspector

    安装相应的包和组件 yum install openstack-ironic-inspector python-ironic-inspector-client -y 创建user openstack ...

  10. Small组件化重构安卓项目

    如果从一开始就没有设计好 后面项目业务比较大的时候很难掉头