时间限制:0.5s

空间限制:6M

题意:

显然就是求一个无源汇有上下界的网络流的可行流的问题

Solution:

没什么好说的,直接判定可行流,输出就好了

code

/*
无汇源有上下界的网络流
*/
#include <iostream>
#include <cstring>
#define ms(a,b) memset(a,b,sizeof a)
using namespace std;
const int MAXN = ; struct node {
int u, v, c, ne;
} edge[MAXN * MAXN << ];
int pHead[MAXN*MAXN], SS, ST, T, ncnt, ans;
int Gup[MAXN][MAXN], Glow[MAXN][MAXN], st[MAXN], ed[MAXN], cap[MAXN][MAXN], tflow; void addEdge (int u, int v, int c) {
edge[++ncnt].v = v, edge[ncnt].c = c, edge[ncnt].u = u;
edge[ncnt].ne = pHead[u], pHead[u] = ncnt;
edge[++ncnt].v = u, edge[ncnt].c = , edge[ncnt].u = v;
edge[ncnt].ne = pHead[v], pHead[v] = ncnt;
} int SAP (int pStart, int pEnd, int N) {
int numh[MAXN], h[MAXN], curEdge[MAXN], pre[MAXN];
int cur_flow, flow_ans = , u, neck, i, tmp;
ms (h, ); ms (numh, ); ms (pre, -);
for (i = ; i <= N; i++) curEdge[i] = pHead[i];
numh[] = N;
u = pStart;
while (h[pStart] <= N) {
if (u == pEnd) {
cur_flow = 1e9;
for (i = pStart; i != pEnd; i = edge[curEdge[i]].v)
if (cur_flow > edge[curEdge[i]].c) neck = i, cur_flow = edge[curEdge[i]].c;
for (i = pStart; i != pEnd; i = edge[curEdge[i]].v) {
tmp = curEdge[i];
edge[tmp].c -= cur_flow, edge[tmp ^ ].c += cur_flow;
}
flow_ans += cur_flow;
u = neck;
}
for ( i = curEdge[u]; i != ; i = edge[i].ne) {
if (edge[i].v > N) continue; //重要!!!
if (edge[i].c && h[u] == h[edge[i].v] + ) break;
}
if (i != ) {
curEdge[u] = i, pre[edge[i].v] = u;
u = edge[i].v;
}
else {
if ( == --numh[h[u]]) continue;
curEdge[u] = pHead[u];
for (tmp = N, i = pHead[u]; i != ; i = edge[i].ne) {
if (edge[i].v > N) continue; //重要!!!
if (edge[i].c) tmp = min (tmp, h[edge[i].v]);
}
h[u] = tmp + ;
++numh[h[u]];
if (u != pStart) u = pre[u];
}
}
return flow_ans;
}
int solve (int n) {
SS = n + , ST = n + ;
for (int i = ; i <= n; i++) {
if (ed[i]) addEdge (SS, i, ed[i]);
if (st[i]) addEdge (i, ST, st[i]);
}
int tem = SAP (SS, ST, ST);
if (tem != tflow) return ;
else
return ;
}
int n, m;
int main() {
ios::sync_with_stdio ();
ncnt = ;
cin >> n >> m;
for (int i = , u, v, x, y; i <= m; i++) {
cin >> u >> v >> x >> y;
Gup[u][v] = y, Glow[u][v] = x;
st[u] += x, ed[v] += x;
tflow += x;
addEdge (u, v, y - x);
}
if (solve (n) ) {
cout << "YES\n";
for (int i = , x, y; i <= m * ; i += ) {
x = edge[i].u, y = edge[i].v;
cout << Gup[x][y]-edge[i].c << '\n';
}
}
else
cout << "NO\n";
return ;
}

SGU 194. Reactor Cooling(无源汇有上下界的网络流)的更多相关文章

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

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

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

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

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

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

  4. ZOJ 2314 Reactor Cooling(无源汇有上下界可行流)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 题目大意: 给n个点,及m根pipe,每根pipe用来流躺 ...

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

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

  6. [ZOJ2341]Reactor Cooling解题报告|带上下界的网络流|无源汇的可行流

    Reactor Cooling The terrorist group leaded by a well known international terrorist Ben Bladen is bul ...

  7. Zoj 2314 Reactor Cooling(无源汇有上下界可行流)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 题意:    给n个点,及m根pipe,每根pipe用来流躺液体的,单向 ...

  8. HDU 4940 Destroy Transportation system(无源汇有上下界最大流)

    看不懂题解以及别人说的集合最多只有一个点..... 然后试了下题解的方法http://blog.sina.com.cn/s/blog_6bddecdc0102uzka.html 首先是无源汇有上下界最 ...

  9. hdu 4940 无源汇有上下界最大流

    /* <img src="http://img.blog.csdn.net/20140823174212937?watermark/2/text/aHR0cDovL2Jsb2cuY3N ...

随机推荐

  1. 【转】OpenGL相关函数库介绍

    原文:http://blog.chinaunix.net/uid-20638550-id-1909182.html OpenGL 函数库相关的API有核心库(gl).实用库(glu).辅助库(aux) ...

  2. 折腾iPhone的生活——运营商信号显示数据化

    iOS7以后iphone的信号都是用5个小圆圈显示的,像这样 但是还有种显示方法可以用数字信号显示信号量,比较适合很专注于生活品质的人和对数字有偏爱的人,像这样: 这样还有个好处是可以节约顶部状态栏的 ...

  3. Import larger wordpress xml file

    The maximum size is controlled by two PHP settings: upload_max_filesize, and post_max_size. These ar ...

  4. SRM 409(1-250pt, 1-500pt)

    DIV1 250pt 题意:称string s是vector<string> words的ordered superstring,如果它满足:存在一个数列{x0, x1, x2...xm} ...

  5. 第二十三章、软件安装: RPM, SRPM 与 YUM 功能

    SRPM 的使用 : rpmbuild 包含Source code 的 SRPM 新版的 rpm 已经将 RPM 与 SRPM 的命令分开了,SRPM 使用的是 rpmbuild 这个命令,而不是 r ...

  6. php操作Memcache示例

    <?php //==============================实例化============================ $mem=new Memcache; //====== ...

  7. c#基础语言编程-异常处理

    异常的定义 异常就是程序中的运行时错误,当出现异常时,系统会捕获这个错误并抛出一个异常.若程序没有提供处理该异常的代码,系统会挂起这个程序. 常见异常的类型 System.Exception 最泛化的 ...

  8. C# 获取网页数据、获取本机IP 分类: C# 2014-12-16 14:59 308人阅读 评论(0) 收藏

    说明: (1) http://www.3322.org/dyndns/getip 这个网址可以获取本机IP,读取的内容就是本机IP (2)方法经测试,可以实现. (3)参考:http://www.cn ...

  9. c# 字符串转化成声音 分类: C# 2014-09-24 12:20 316人阅读 评论(0) 收藏

    说明: (1)支持Window 7系统,但是xp系统智能朗读英文和数字: (2)添加引用 Interop.SpeechLib.dll; (3)使用时调用StringToVoice(str)即可. us ...

  10. 基于xmpp openfire smack开发之openfire介绍和部署[1]

    前言 http://blog.csdn.net/shimiso/article/details/8816558 Java领域的即时通信的解决方案可以考虑openfire+spark+smack.当然也 ...