SGU 194. Reactor Cooling(无源汇有上下界的网络流)
时间限制: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(无源汇有上下界的网络流)的更多相关文章
- ZOJ 2314 (sgu 194) Reactor Cooling (无源汇有上下界最大流)
题意: 给定n个点和m条边, 每条边有流量上下限[b,c], 求是否存在一种流动方法使得每条边流量在范围内, 而且每个点的流入 = 流出 分析: 无源汇有上下界最大流模板, 记录每个点流的 in 和 ...
- SGU 194 Reactor Cooling 无源汇带上下界可行流
Reactor Cooling time limit per test: 0.5 sec. memory limit per test: 65536 KB input: standard output ...
- sgu 194 Reactor Cooling(有容量上下界的无源无汇可行流)
[题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20757 [题意] 求有容量上下界的无源无汇可行流. [思路] ...
- ZOJ 2314 Reactor Cooling(无源汇有上下界可行流)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 题目大意: 给n个点,及m根pipe,每根pipe用来流躺 ...
- SGU 194 Reactor Cooling (无源上下界网络流)
The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuclear ...
- [ZOJ2341]Reactor Cooling解题报告|带上下界的网络流|无源汇的可行流
Reactor Cooling The terrorist group leaded by a well known international terrorist Ben Bladen is bul ...
- Zoj 2314 Reactor Cooling(无源汇有上下界可行流)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 题意: 给n个点,及m根pipe,每根pipe用来流躺液体的,单向 ...
- HDU 4940 Destroy Transportation system(无源汇有上下界最大流)
看不懂题解以及别人说的集合最多只有一个点..... 然后试了下题解的方法http://blog.sina.com.cn/s/blog_6bddecdc0102uzka.html 首先是无源汇有上下界最 ...
- hdu 4940 无源汇有上下界最大流
/* <img src="http://img.blog.csdn.net/20140823174212937?watermark/2/text/aHR0cDovL2Jsb2cuY3N ...
随机推荐
- 【转】压缩Virtualbox的vdi文件
原文网址:http://i.rexdf.org/blog/2014/10/06/ya-suo-virtualboxde-vdiwen-jian/ 问题实际上比较简单,我在Arch Linux杂记中给出 ...
- U盘安装 OSX
首先,刚从app store下载完的OS X Lion会放在屏幕下方的Dock中. 用鼠标将Mac OS X Lion 10.7文件从Dock中拖放到桌面. 右键单击Mac OS X Lion 10. ...
- 在unity3d中连接sql server
虽然在Unity3D中能够通过PlayerPrefs类来保存和读取数据,但是一旦数据量增大,仅仅通过代码的方式存取数据,这样的工作量是非常大的.那么如何通过使用Sql Server数据库来存取数据呢? ...
- UVa 10294 Arif in Dhaka (First Love Part 2)(置换)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35397 [思路] Polya定理. 旋转:循环节为gcd(i,n) ...
- AC自动机——多模式串匹配的算法思想
标准KMP算法用于单一模式串的匹配,即在母串中寻求一个模式串的匹配,但是现在又存在这样的一个问题,如果同时给出多个模式串,要求找到这一系列模式串在母串存在的匹配个数,我们应该如何处理呢? 基于KMP算 ...
- BCTF赛后
今天早上八点,BTCF第一届落幕.虽然没有熬夜coding但还是十分开心. 从收到超哥的邀请,到回头组队,一开始的十几人,最后演化为五人的精简小分队,到昨晚把所有有想法的题目全部搞定,十分的开心和欣慰 ...
- 常用Dos命令笔记
0x00 磁盘FAT32格式转NTFS convert e: /fs:ntfs Tips: 语法规则: Converts a FAT volume to NTFS. CONVERT volume /F ...
- 初次接触GWT,知识点总括
初次接触GWT,知识点概括 前言 本人最近开始研究 GWT(Google Web Toolkit) ,现将个人的一点心得贴出来,希望对刚开始接触 GWT的程序员们有所帮助,也欢迎讨论,共同进步. 先说 ...
- delphi TFontDialog
设置前先获得Memo的字体属性并设置给FontDialog 然后再设置MEMO的字体属性 //设置Memo的字体属性 procedure TForm1.mni_FontClick(Sender ...
- 实用技巧:简单而有用的nohup命令介绍(转)
简单而有用的nohup命令在UNIX/LINUX中,普通进程用&符号放到后台运行,如果启动该程序的控制台logout,则该进程随即终止. 要实现守护进程,一种方法是按守护进程的规则去编程(本站 ...