UVA_10030

对于题目中每个点的容量的限制,我们可以把一个点i拆成两个点2*i和2*i ^ 1,并连一条有向边2*i->2*i^1,容量为该点的容量限制,在建图的时候从2*i流入并从2*i^1流出即可。

#include<stdio.h>#include<string.h>#define MAXD 210#define MAXM 81000#define INF 100000000int N, flow[MAXM], first[MAXD], next[MAXM], u[MAXM], v[MAXM], e;int work[MAXD], d[MAXD], q[MAXD];int add(int a, int b, int w){    u[e] = a;    v[e] = b;    flow[e] = w;    next[e] = first[a];    first[a] = e;    e ++;}int init(){int i, j, a, b, w, M, B, D;if(scanf("%d", &N) != 1)return 0;    e = 0;    memset(first, -1, sizeof(first));for(i = 1; i <= N; i ++)    {        scanf("%d", &w);        add(2 * i, 2 * i ^ 1, w);        add(2 * i ^ 1, 2 * i, 0);    }    scanf("%d", &M);for(i = 0; i < M; i ++)    {        scanf("%d%d%d", &a, &b, &w);        add(2 * a ^ 1, 2 * b, w);        add(2 * b, 2 * a ^ 1, 0);    }    scanf("%d%d", &B, &D);for(i = 0; i < B; i ++)    {        scanf("%d", &j);        add(0, 2 * j, INF);        add(2 * j, 0, 0);    }for(i = 0; i < D; i ++)    {        scanf("%d", &j);        add(2 * j ^ 1, 1, INF);        add(1, 2 * j ^ 1, 0);    }return 1;}int bfs(){int i, j, rear;    memset(d, -1, sizeof(d));    d[0] = 0;    rear = 0;    q[rear ++] = 0;for(i = 0; i < rear; i ++)for(j = first[q[i]]; j != -1; j = next[j])if(d[v[j]] == -1 && flow[j])            {                d[v[j]] = d[q[i]] + 1;if(v[j] == 1)return 1;                q[rear ++] = v[j];            }return 0;}int dfs(int cur, int a){if(cur == 1)return a;for(int &i = work[cur]; i != -1; i = next[i])if(flow[i] && d[v[i]] == d[cur] + 1)if(int t = dfs(v[i], a < flow[i] ? a : flow[i]))            {                flow[i] -= t;                flow[i ^ 1] += t;return t;            }return 0;}int dinic(){int res = 0, t;while(bfs())    {        memcpy(work, first, sizeof(first));while(t = dfs(0, INF))            res += t;    }return res;}int main(){while(init())    {int res = dinic();        printf("%d\n", res);    }return 0;}

转载于:https://www.cnblogs.com/staginner/archive/2011/10/14/2212200.html

UVA 10330 Power Transmission相关推荐

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

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

  2. Power Transmission

    (Easy Edition) https://codeforces.com/contest/1163/problem/C1 (Hard Edition) https://codeforces.com/ ...

  3. 12行代码AC——UVa 151 - Power Crisis(约瑟夫环)

    励志用尽量少的代码做高效表达. 提交(题目)链接-->UVa-151 题意 有n个电场,按约瑟夫环的规则断电,最后一个不断电,要求将最后一个断电的电场停在13号. 分析 约瑟夫环公式:f(N,M ...

  4. 提取了下刘汝佳推荐的题号...

    今天闲来没事上uva oj提取了下刘汝佳推荐的acm题号,原始数据如下: Volume 0. Getting Started    10055 - Hashmat the Brave Warrior ...

  5. UVa Online Judge 工具網站

    UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...

  6. Wireless Power Tranmissions

    Some Major Wireless Power Tranmissions 电子科技大学 格拉斯哥学院 高浩淳 2017/18级 Abstract: Wireless power transmiss ...

  7. 矩阵模板hdu5015,UVA 10655,UVA 11149

    hdu5015 n是<=10的,可以想到点什么,, 构造矩阵mat[n+2][n+2] 发现mat*a是答案矩阵第1列 mat的m次方再乘a就是答案矩阵的第m列,取最下面的就行了 这板不错 #i ...

  8. 电路Circuit-Chapter 11 AC Power Analysis

    Chapter 11 AC power Analysis 11.1 Introduction 11.2 Instantaneous and Average Power(瞬时功率和平均功率) 中文部分 ...

  9. ACM比赛经验、刷题记录及模板库总结(更新中)

    前言 本文所提及的部分题目代码,可以在我的Github上找到 第一部分 经验分享及感受 第二部分 刷题记录 一.基础算法&程序语言 //strlen()函数的复杂度是O(n)要小心 //截取字 ...

  10. 紫书《算法竞赛入门经典》

    紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...

最新文章

  1. HTTPS 的工作原理
  2. 从0搭建一个Springboot+vue前后端分离项目(二)使用idea进行页面搭建+页面搭建
  3. VTK:Points之SignedDistance
  4. java web 邮箱激活 与 忘记密码(重置密码)
  5. [转]解决Windows 7下Windows Live Messenger(MSN) 9.0在一直停靠任务栏而不在系统栏显示的问题...
  6. python os.path.exists判断文件或文件夹是否存在
  7. 前端学习(2815):小程序学习之开发者工具介绍
  8. hadoop3.0.3 SLS-Failed to create an AM
  9. 微型计算机的软件系统分为哪几类,系统软件分为哪几类?各有什么特点?
  10. c语言5的阶乘流程图_C语言程序设计(山东联盟)
  11. linux救援模式详解,Linux系统的救援模式应用详解
  12. 安规认证的测试项目(工程师必须知道的知识)
  13. 现代计算机的存储体系 (转载)
  14. 【ICML 2020联邦学习论文解读】SCAFFOLD: Stochastic Controlled Averaging for Federated Learning
  15. Unity2D愤怒的小鸟技术点总结 ---- 制作动画特效
  16. 用计算机打女生节快乐,二十好几还没女朋友?女神节的打开方式出了问题
  17. 刷宝短视频Auto.js挂机源码讲解
  18. Lesson 18 He often does this! 他经常干这种事!
  19. WINDOWS 疑难杂症
  20. 前端国际化,用jquery.i18n完成中英文切换

热门文章

  1. linux下NIS服务的配置
  2. PHP设计模式——迭代器模式
  3. 初识NB-IoT的机卡绑定
  4. 咏南中间件D7客户端演示
  5. java设计模式-Observe
  6. Leetcode 242.有效的字母异位词 By Python
  7. CentOS 5.8/6.7若干优化
  8. jar包的生成及运行
  9. leaflet 的 marker 弹框 iframe 嵌套代码
  10. tensorflow分布式运行