ZOJ2314 Reactor Cooling(有上下界的网络流)
The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuclear reactor to produce plutonium for the nuclear bomb they are planning to create. Being the wicked computer genius of this group, you are responsible for developing the cooling system for the reactor.
The cooling system of the reactor consists of the number of pipes that special cooling liquid flows by. Pipes are connected at special points, called nodes, each pipe has the starting node and the end point. The liquid must flow by the pipe from its start point to its end point and not in the opposite direction.
Let the nodes be numbered from 1 to N. The cooling system must be designed so that the liquid is circulating by the pipes and the amount of the liquid coming to each node (in the unit of time) is equal to the amount of liquid leaving the node. That is, if we designate the amount of liquid going by the pipe from i-th node to j-th as fij, (put fij = 0 if there is no pipe from node i to node j), for each i the following condition must hold:
fi,1+fi,2+...+fi,N = f1,i+f2,i+...+fN,i
Each pipe has some finite capacity, therefore for each i and j connected by the pipe must be fij <= cij where cij is the capacity of the pipe. To provide sufficient cooling, the amount of the liquid flowing by the pipe going from i-th to j-th nodes must be at least lij, thus it must be fij >= lij.
Given cij and lij for all pipes, find the amount fij, satisfying the conditions specified above.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
The first line of the input file contains the number N (1 <= N <= 200) - the number of nodes and and M - the number of pipes. The following M lines contain four integer number each - i, j, lij and cij each. There is at most one pipe connecting any two nodes and 0 <= lij <= cij <= 10^5 for all pipes. No pipe connects a node to itself. If there is a pipe from i-th node to j-th, there is no pipe from j-th node to i-th.
Output
On the first line of the output file print YES if there is the way to carry out reactor cooling and NO if there is none. In the first case M integers must follow, k-th number being the amount of liquid flowing by the k-th pipe. Pipes are numbered as they are given in the input file.
Sample Input
2
4 6
1 2 1 2
2 3 1 2
3 4 1 2
4 1 1 2
1 3 1 2
4 2 1 2
4 6
1 2 1 3
2 3 1 3
3 4 1 3
4 1 1 3
1 3 1 3
4 2 1 3
Sample Input
NO
YES
1
2
3
2
1
1
有上下界的网络流可行流:
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=;
const int inf=;
int Laxt[maxn],Next[maxn],To[maxn],Cap[maxn],cnt;
int dis[maxn],nd[maxn],S,T,num,ans,q[maxn],qnum[maxn],top;
void init()
{
cnt=;ans=num=top=;
memset(Laxt,,sizeof(Laxt));
memset(dis,,sizeof(dis));
memset(nd,,sizeof(nd));
}
int add(int u,int v,int c)
{
Next[++cnt]=Laxt[u];
Laxt[u]=cnt;
To[cnt]=v;
Cap[cnt]=c; Next[++cnt]=Laxt[v];
Laxt[v]=cnt;
To[cnt]=u;
Cap[cnt]=;
}
int sap(int u,int flow)
{
if(u==T||flow==) return flow;
int delta=,tmp;
for(int i=Laxt[u];i;i=Next[i]){
int v=To[i];
if(dis[v]+==dis[u]&&Cap[i]>){
tmp=sap(v,min(Cap[i],flow-delta));
delta+=tmp;
Cap[i]-=tmp;
Cap[i^]+=tmp;
if(flow==delta||dis[]>=T) return delta;
}
}
nd[dis[u]]--;
if(nd[dis[u]]==) dis[]=T;
nd[++dis[u]]++;
return delta;
}
int main()
{
int Case,n,i,j,m,u,v,x,y;
scanf("%d",&Case);
while(Case--){
init();
scanf("%d%d",&n,&m);
S=;T=n+;
for(i=;i<=m;i++){
scanf("%d%d%d%d",&u,&v,&x,&y);
u++;v++;num+=x;
add(u,v,y-x);
q[++top]=cnt;
qnum[top]=x;
add(S,v,x);
add(u,T,x);
}
while(dis[S]<T) {
ans+=sap(S,inf);
}
if(num!=ans) printf("NO\n");
else {
printf("YES\n");
for(i=;i<=top;i++) printf("%d\n",Cap[q[i]]+qnum[i]);
}
if(T) printf("\n");
}
return ;
}
分享三张图



看完后应该就能理解了。具体的以后再慢慢整理咯。
ZOJ2314 Reactor Cooling(有上下界的网络流)的更多相关文章
- ZOJ 2314 Reactor Cooling 带上下界的网络流
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 题意: 给n个点,及m根pipe,每根pipe用来流躺液体的, ...
- 【zoj2314】Reactor Cooling 有上下界可行流
题目描述 The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuc ...
- SGU 194 Reactor Cooling (无源上下界网络流)
The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuclear ...
- 【ZOJ2314】Reactor Cooling(有上下界的网络流)
前言 话说有上下界的网络流好像全机房就我一个人会手动滑稽,当然这是不可能的 Solution 其实这道题目就是一道板子题,主要讲解一下怎么做无源无汇的上下界最大流: 算法步骤 1.将每条边转换成0~u ...
- SGU 194. Reactor Cooling(无源汇有上下界的网络流)
时间限制:0.5s 空间限制:6M 题意: 显然就是求一个无源汇有上下界的网络流的可行流的问题 Solution: 没什么好说的,直接判定可行流,输出就好了 code /* 无汇源有上下界的网络流 * ...
- ACM/ICPC 之 有流量上下界的网络流-Dinic(可做模板)(POJ2396)
//有流量上下界的网络流 //Time:47Ms Memory:1788K #include<iostream> #include<cstring> #include<c ...
- ZOJ 2314 有上下界的网络流
problemCode=2314">点击打开链接 题意:给定m条边和n个节点.每条边最少的流量和最多的流量.保证每一个节点的出入流量和相等,问能够形成吗,能够则输出每条边的流量 思路: ...
- poj_2396 有上下界的网络流
题目大意 一个mxn的矩阵,给出矩阵中每一行的和sh[1,2...m]以及每一列的数字的和目sv[1,2...n],以及矩阵中的一些元素的范围限制,比如a[1][2] > 1, a[2][3] ...
- 【BZOJ2502】清理雪道 有上下界的网络流 最小流
[BZOJ2502]清理雪道 Description 滑雪场坐落在FJ省西北部的若干座山上. 从空中鸟瞰,滑雪场可以看作一个有向无环图,每条弧代表一个斜坡(即雪道),弧的方向代表斜坡下降 ...
随机推荐
- python删除列表中所有的空元素
while '' in list: list.remove('')
- spark学习(2)--hadoop安装、配置
环境: 三台机器 ubuntu14.04 hadoop2.7.5 jdk-8u161-linux-x64.tar.gz (jdk1.8) 架构: machine101 :名称节点.数据节点.Secon ...
- OC导入框架方式#import、@import的区别
#import负责导入程序所需的文件的信息导入到程序中,随着程序所需的文件越来越多,程序就要导入更多的文件,这就带来了越来越长的编译时间,而且有大量重复的.为了解决这个问题可以采用以下办法解决,创建. ...
- Java 集合系列13之 TreeMap详细介绍(源码解析)和使用示例
转载 http://www.cnblogs.com/skywang12345/p/3310928.html https://www.jianshu.com/p/454208905619
- ETL应用:一种一次获取一个平台接口文件的方法
ETL应用场景中,若对端接口文件未能提供,任务会处于循环等待,直到对端提供为止,该方法极大的消耗了系统资源.为此想到了一种方法,一次获取一个平台的文件,实现思路如下: 1.第一次获取对端平台提供目录下 ...
- 试坑不完美的 clip-path (我说的 CSS 的那个)
需求跟我说,咱们要创新,想做一个蜂巢状的列表,年少无知的我竟然一口答应了,全然因为刚接触了 clip-path: But,然而,不幸的是,这只是坎坷路途的开始.... clip-path 的教程很多了 ...
- Emgu在引用openCV时提示:无法加载 DLL“opencv_core2410”: 找不到指定的模块。
在引用开源代码openCV时发现了如下问题: 无法加载 DLL“opencv_core2410”: 找不到指定的模块. (异常来自 HRESULT:0x8007007E). 解决方法如下: 将Emgu ...
- Linux启动ssh服务
Linux启动ssh服务 在Linux下启动ssh服务使用如下命令其一即可: # service sshd start # /etc/init.d/sshd start 开机启动 使用如下方法其就可以 ...
- Kubernetes Metrics-Server
github地址:https://github.com/kubernetes-incubator/metrics-server 官网介绍:https://kubernetes.io/docs/task ...
- kafka笔记(一)
1.kafka应用场景 基于流数据的发布订阅消息系统.实时流数据的高效异步通信.基于流数据的高可用分布式存储! 不同的系统之间实时流数据管道; 2.官方一句话概括 kafka是一个分布式流数据平台:可 ...