题意:给定上一个有容量和下界的网络,让你求出一组可行解。

析:先建立一个超级源点 s 和汇点 t ,然后在输入时记录到每个结点的下界的和,建边的时候就建立c - b的最后再建立 s 和 t , 在建立时,如果 i 结点的输入的大于输出的,那么就是从 s 建立一条边,否则 i 与 t 建立,然后跑一次最大流,就OK了,注意求出的流量是没有下界,再加上下界的就好了。

代码如下:

  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include <cstdio>
  3. #include <string>
  4. #include <cstdlib>
  5. #include <cmath>
  6. #include <iostream>
  7. #include <cstring>
  8. #include <set>
  9. #include <queue>
  10. #include <algorithm>
  11. #include <vector>
  12. #include <map>
  13. #include <cctype>
  14. #include <cmath>
  15. #include <stack>
  16. #include <sstream>
  17. #include <list>
  18. #include <assert.h>
  19. #include <bitset>
  20. #define debug() puts("++++");
  21. #define gcd(a, b) __gcd(a, b)
  22. #define lson l,m,rt<<1
  23. #define rson m+1,r,rt<<1|1
  24. #define fi first
  25. #define se second
  26. #define pb push_back
  27. #define sqr(x) ((x)*(x))
  28. #define ms(a,b) memset(a, b, sizeof a)
  29. #define sz size()
  30. #define pu push_up
  31. #define pd push_down
  32. #define cl clear()
  33. #define all 1,n,1
  34. #define FOR(x,n) for(int i = (x); i < (n); ++i)
  35. #define freopenr freopen("in.txt", "r", stdin)
  36. #define freopenw freopen("out.txt", "w", stdout)
  37. using namespace std;
  38.  
  39. typedef long long LL;
  40. typedef unsigned long long ULL;
  41. typedef pair<int, int> P;
  42. const int INF = 0x3f3f3f3f;
  43. const LL LNF = 1e16;
  44. const double inf = 1e20;
  45. const double PI = acos(-1.0);
  46. const double eps = 1e-8;
  47. const int maxn = 200 + 50;
  48. const int mod = 1000;
  49. const int dr[] = {-1, 0, 1, 0};
  50. const int dc[] = {0, 1, 0, -1};
  51. const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
  52. int n, m;
  53. const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  54. const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  55. inline bool is_in(int r, int c){
  56. return r > 0 && r <= n && c > 0 && c <= m;
  57. }
  58. struct Edge{
  59. int from, to, cap, flow;
  60. };
  61.  
  62. struct Dinic{
  63. int n, m, s, t;
  64. vector<Edge> edges;
  65. vector<int> G[maxn];
  66. bool vis[maxn];
  67. int d[maxn];
  68. int cur[maxn];
  69.  
  70. void init(int n){
  71. this-> n = n;
  72. edges.clear();
  73. for(int i = 0; i < n; ++i) G[i].clear();
  74. }
  75.  
  76. void addEdge(int from, int to, LL cap){
  77. edges.push_back((Edge){from, to, cap, 0});
  78. edges.push_back((Edge){to, from, 0, 0});
  79. m = edges.size();
  80. G[from].push_back(m-2);
  81. G[to].push_back(m-1);
  82. }
  83.  
  84. bool bfs(){
  85. memset(vis, 0, sizeof vis);
  86. queue<int> q;
  87. q.push(s);
  88. d[s] = 0;
  89. vis[s] = 1;
  90. while(!q.empty()){
  91. int x = q.front(); q.pop();
  92. for(int i = 0; i < G[x].size(); ++i){
  93. Edge &e = edges[G[x][i]];
  94. if(!vis[e.to] && e.cap > e.flow){
  95. vis[e.to] = 1;
  96. d[e.to] = d[x] + 1;
  97. q.push(e.to);
  98. }
  99. }
  100. }
  101. return vis[t];
  102. }
  103.  
  104. int dfs(int x, int a){
  105. if(x == t || a == 0) return a;
  106. int flow = 0, f;
  107. for(int &i = cur[x]; i < G[x].size(); ++i){
  108. Edge &e = edges[G[x][i]];
  109. if(d[x] + 1 == d[e.to] && (f = dfs(e.to, min(a, e.cap-e.flow))) > 0){
  110. e.flow += f;
  111. edges[G[x][i]^1].flow -= f;
  112. flow += f;
  113. a -= f;
  114. if(a == 0) break;
  115. }
  116. }
  117. return flow;
  118. }
  119.  
  120. int maxFlow(int s, int t){
  121. this->s = s; this->t = t;
  122. int flow = 0;
  123. while(bfs()){
  124. memset(cur, 0, sizeof cur);
  125. flow += dfs(s, INF);
  126. }
  127. return flow;
  128. }
  129. };
  130. Dinic dinic;
  131. int in[maxn*maxn], out[maxn*maxn];
  132. int B[maxn*maxn];
  133.  
  134. int main(){
  135. scanf("%d %d", &n, &m);
  136. int s = 0, t = n + 1;
  137. for(int i = 0; i < m; ++i){
  138. int u, v, b, c;
  139. scanf("%d %d %d %d", &u, &v, &b, &c);
  140. dinic.addEdge(u, v, c - b);
  141. B[i] = b;
  142. in[v] += b; out[u] += b;
  143. }
  144. int ans = 0;
  145. for(int i = 1; i <= n; ++i){
  146. int c = in[i] - out[i];
  147. if(c > 0) dinic.addEdge(s, i, c), ans += c;
  148. else dinic.addEdge(i, t, -c);
  149. }
  150. if(dinic.maxFlow(s, t) != ans){ puts("NO"); return 0; }
  151. puts("YES");
  152. for(int i = 0; i < m; ++i)
  153. printf("%d\n", dinic.edges[i<<1].flow + B[i]);
  154. return 0;
  155. }

  

SGU 194 Reactor Cooling (有容量和下界的可行流)的更多相关文章

  1. sgu 194 Reactor Cooling(有容量上下界的无源无汇可行流)

    [题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20757 [题意] 求有容量上下界的无源无汇可行流. [思路] ...

  2. SGU 194 Reactor Cooling(无源无汇上下界可行流)

    Description The terrorist group leaded by a well known international terrorist Ben Bladen is bulidin ...

  3. SGU 194 Reactor Cooling (无源上下界网络流)

    The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuclear ...

  4. SGU 194 Reactor Cooling 无源汇带上下界可行流

    Reactor Cooling time limit per test: 0.5 sec. memory limit per test: 65536 KB input: standard output ...

  5. SGU 194 Reactor Cooling Dinic求解 无源无汇有上下界的可行流

    题目链接 题意:有向图中有n(1 <= n <= 200)个点,无自环或者环的节点个数至少为3.给定每条边的最小流量和最大流量,问每条边的可行流量为多少? 思路:一般求解的网络流并不考虑下 ...

  6. SGU 194. Reactor Cooling(无源汇有上下界的网络流)

    时间限制:0.5s 空间限制:6M 题意: 显然就是求一个无源汇有上下界的网络流的可行流的问题 Solution: 没什么好说的,直接判定可行流,输出就好了 code /* 无汇源有上下界的网络流 * ...

  7. SGU 194 Reactor Cooling ——网络流

    [题目分析] 无源汇上下界可行流. 上下界网络流的问题可以参考这里.↓ http://www.cnblogs.com/kane0526/archive/2013/04/05/3001108.html ...

  8. 【无源汇上下界最大流】SGU 194 Reactor Cooling

    题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=194 题目大意: n个点(n<20000!!!不是200!!!RE了无数次) ...

  9. ZOJ 2314 (sgu 194) Reactor Cooling (无源汇有上下界最大流)

    题意: 给定n个点和m条边, 每条边有流量上下限[b,c], 求是否存在一种流动方法使得每条边流量在范围内, 而且每个点的流入 = 流出 分析: 无源汇有上下界最大流模板, 记录每个点流的 in 和 ...

随机推荐

  1. linux之 CentOS/RHEL/Scientific Linux 6 & 7上安装Telnet

    声明: 在安装和使用Telnet之前,需要记住以下几点. 在公网(WAN)中使用Telnet是非常不好的想法.它会以明文的格式传输登入数据.每个人都可以看到明文.如果你还是需要Telnet,强烈建议你 ...

  2. 开始SDK之旅-入门1基本环境搭建与测试

    已验证这个可用. http://bbs.ccflow.org/showtopic-2560.aspx 集成方式已经用一段时间了,今天刚好有时间,尝试下SDK.使用的话,也很方便,以下是简单的步骤1.新 ...

  3. opencv中读取显示图像

    opencv是个开源的图像处理的库,小到基本的图像处理函数,如图像移动放大缩小,大到人脸识别,部分机器学习的知识,所以是个学习的不错的库.之前有图像处理的知识,这次再学习下这个开源库. 先上基础的图像 ...

  4. Java 中的包装类

    Java 中的包装类 相信各位小伙伴们对基本数据类型都非常熟悉,例如 int.float.double.boolean.char 等.基本数据类型是不具备对象的特性的,比如基本类型不能调用方法.功能简 ...

  5. Bootstrap-Other:CSS编码规范

    ylbtech-Bootstrap-Other:CSS编码规范 1.返回顶部 1. Bootstrap CSS编码规范 语法 用两个空格来代替制表符(tab) -- 这是唯一能保证在所有环境下获得一致 ...

  6. FancyButtons一个漂亮按钮的库

      一个功能强大且全面的按钮控件,是目前我见过的最好使的按钮. 支持给按钮添加图标,并且可通过属性设置手指按钮的效果,不需要在写<selector>文件. 项目地址:https://git ...

  7. springboot 2.0 自定义redis自动装配

    首先创建maven项目 pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xm ...

  8. String(byte[] bytes, Charset charset) 和 getBytes() 使用

    转自:https://techbirds.iteye.com/blog/1855960 @Test public void testBytes(){ //字节数 //中文:ISO:1 GBK:2 UT ...

  9. asp.net 初级程序员面试题【待续】

     C# 常见的排序方式 冒泡排序(Bubble sort) 堆排序(Heap sort) 插入排序(Insertion sort) 归并排序(Merge sort) 快速排序(Quick sort) ...

  10. 智能指针--C++

    智能指针(一):STL auto_ptr实现原理 智能指针实际上是一个类(class),里面封装了一个指针.它的用处是啥呢? 指针与内存 说到指针自然涉及到内存.我们如果是在堆栈(stack)中分配了 ...