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 f ij, (put f ij = 0 if there is no pipe from node i to node j), for each i the following condition must hold: 

sum(j=1..N, f ij) = sum(j=1..N, f ji
Each pipe has some finite capacity, therefore for each i and j connected by the pipe must be f ij ≤ c ij where c ij 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 l ij, thus it must be f ij ≥ l ij
Given c ij and l ij for all pipes, find the amount f ij, satisfying the conditions specified above. 
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, l ij and c ij each. There is at most one pipe connecting any two nodes and 0 ≤ l ij ≤ c ij ≤ 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 test(s)
Input
 
 
Test #1

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

Test #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 

 
 
Output
 
 
Test #1

NO

Test #2

YES 





 
一个网络没有源点汇点,里面留着液体,每条边除了流量有上限之外还有下限,问是否能满足所有边的流量约束,能的话输出每条边的流量
如果没有下界我们是会做的,其实下界就是0,我们建边的时候u到v建一条容量r-l的边,这样下界就是0了
此时我们需要平衡流量,我们虚拟一个源点与汇点,对于每条边的u,v.从源点连一条容量为l的边到v,从汇点连一条容量为l的边到u
这样我们就平衡了流量.然后跑最大流.
如果最大流等于与源点相连的边的流量(其实就是每个边的下界之和)就可行
 #include <bits/stdc++.h>

 using namespace std;
const int maxn = ;
const int inf = 0x3f3f3f3f;
struct Edge
{
int from,to,cap,flow;
Edge (int f,int t,int c,int fl)
{
from=f,to=t,cap=c,flow=fl;
}
};
struct Dinic
{
int n,m,s,t;
vector <Edge> edge;
vector <int> G[maxn];//存图
bool vis[maxn];//标记每点是否vis过
int cur[maxn];//当前弧优化
int dep[maxn];//标记深度
void init(int n,int s,int t)//初始化
{
this->n=n;this->s=s;this->t=t;
edge.clear();
for (int i=;i<n;++i) G[i].clear();
}
void addedge (int from,int to,int cap)//加边,单向边
{
edge.push_back(Edge(from,to,cap,));
edge.push_back(Edge(to,from,,));
m=edge.size();
G[from].push_back(m-);
G[to].push_back(m-);
}
bool bfs ()
{
queue<int> q;
while (!q.empty()) q.pop();
memset(vis,false,sizeof vis);
vis[s]=true;
dep[s]=;
q.push(s);
while (!q.empty()){
int u=q.front();
//printf("%d\n",u);
q.pop();
for (int i=;i<G[u].size();++i){
Edge e=edge[G[u][i]];
int v=e.to;
if (!vis[v]&&e.cap>e.flow){
vis[v]=true;
dep[v]=dep[u]+;
q.push(v);
}
}
}
return vis[t];
}
int dfs (int x,int mi)
{
if (x==t||mi==) return mi;
int flow=,f;
for (int &i=cur[x];i<G[x].size();++i){
Edge &e=edge[G[x][i]];
int y=e.to;
if (dep[y]==dep[x]+&&(f=dfs(y,min(mi,e.cap-e.flow)))>){
e.flow+=f;
edge[G[x][i]^].flow-=f;
flow+=f;
mi-=f;
if (mi==) break;
}
}
return flow;
}
int max_flow ()
{
int ans = ;
while (bfs()){
memset(cur,,sizeof cur);
ans+=dfs(s,inf);
}
return ans;
}
}dinic;
int full_flow;
int n,m;
int id[maxn];
int low[maxn];
int main()
{
//freopen("de.txt","r",stdin);
while (~scanf("%d%d",&n,&m)){
full_flow = ;
int src = ,dst = n+;
dinic.init(maxn,src,dst);
for (int i=;i<=m;++i){
int u,v,l,r;
scanf("%d%d%d%d",&u,&v,&l,&r);
//printf("%d %d %d %d\n",u,v,l,r);
full_flow+=l;
low[i]=l;
dinic.addedge(u,v,r-l);
id[i] = dinic.edge.size()-;
//printf("%d %d %d\n",dinic.edge[id[i]].from,dinic.edge[id[i]].to,dinic.edge[id[i]].cap);
dinic.addedge(src,v,l);
dinic.addedge(u,dst,l);
}
if (dinic.max_flow()!=full_flow){
printf("NO\n");
}
else{
printf("YES\n");
for (int i=;i<=m;++i){
printf("%d\n",low[i]+dinic.edge[id[i]].flow);
}
}
}
return ;
}

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

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

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

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

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

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

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

  4. SGU 194 Reactor Cooling ——网络流

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

  5. 【zoj2314】Reactor Cooling 有上下界可行流

    题目描述 The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuc ...

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

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

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

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

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

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

  9. ZOJ 2314 Reactor Cooling 带上下界的网络流

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

随机推荐

  1. webService接口的py文件打包成exe

    (一)webService接口的py文件打包成exe,在python3.5版本.pyInstaller3.2版本.pywin32-219.win-amd64-py3.5版本打包时报错,原因可能是pyi ...

  2. delphi中的idhttpserver如何才能收到idhttp发送来的exe\rar文件呢

    http://zhidao.baidu.com/link?url=-q2oXqYCKBZ9OgFDEHAcQwQEY_NroHcqGvVfKW67X5sF9LdjAAB_HPXQo04VxStFVS7 ...

  3. js面向对象程序设计之属性和对象

    写在博客之前的话,这是我这个刚毕业的菜鸟的第一篇博客.一口吃不成一个胖子,我也希望写的第一篇东西就让读的人醍醐灌顶.我会抱着怀疑的态度来看自己写的文章,如果有写错的地方,请大家不要被误导,如果有大神提 ...

  4. Js类的静态方法与实例方法区分以及jQuery如何拓展两种方法

    上学时C#老师讲到对象有两类方法,静态方法(Static)和实例方法(非Static),当时不理解静态是为何意,只是强记. 后来从事前端工作,一直在对类(即对象,Js中严格来说没有类的定义,虽众所周知 ...

  5. canvas添加事件

    https://blog.csdn.net/xundh/article/details/78722744

  6. flex布局解说和属性

    1. flex-direction 规定当前DIV下面的子元素是横向布局还是纵向布局 row 默认值,横向布局相当于float:left column 纵向,相当于DIV默认的垂直方向 2.justi ...

  7. #python# 代理过程中遇到的error

    做一下总结 urllib.error.HTTPError: HTTP Error 503: Too many open connections TimeoutError: [WinError 1006 ...

  8. Java 小技巧和在Java避免NullPonintException的最佳方法(翻译)

                前几天就g+里面看到有人引用这篇博文.看了一下.受益颇多. 所以翻译过来,希望和大家一起学习.本人英语水平有限,假设有错,请大家指正. 原文地址(须要翻墙):http://ja ...

  9. Oracle ORA-01033: ORACLE initialization or shutdown in progress 错误解决办法. 重启服务

    今天用Oracle突然出现Oracle ORA-01033: ORACLE initialization or shutdown in progress. 想起前两天删掉了几个DBF文件,幸好还没有清 ...

  10. asp.net ajax的使用

    参考:https://www.cnblogs.com/acles/articles/2385648.html https://www.cnblogs.com/xujingyang/p/5560646. ...