题意: 给n个点,及m根pipe,每根pipe用来流躺液体的,单向的,每时每刻每根pipe流进来的物质要等于流出去的物质,要使得m条pipe组成一个循环体,里面流躺物质。

并且满足每根pipe一定的流量限制,范围为[Li,Ri].即要满足每时刻流进来的不能超过Ri(最大流问题),同时最小不能低于Li。

/*
无源汇的上下界可行流。
参见:周源《一种简易的方法求解流量有上下界的网络中网络流问题》。
*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#define N 210
#define M 80010
#define inf 1000000000
using namespace std;
int head[N],dis[N],low[M],s[N],n,m,cnt,S,T;
struct node{int v,f,pre;}e[M];
queue<int> q;
void add(int u,int v,int f){
e[++cnt].v=v;e[cnt].f=f;e[cnt].pre=head[u];head[u]=cnt;
e[++cnt].v=u;e[cnt].f=;e[cnt].pre=head[v];head[v]=cnt;
}
bool bfs(){
memset(dis,-,sizeof(dis));
q.push(S);dis[S]=;
while(!q.empty()){
int u=q.front();q.pop();
for(int i=head[u];i;i=e[i].pre)
if(e[i].f&&dis[e[i].v]==-){
dis[e[i].v]=dis[u]+;
q.push(e[i].v);
}
}
return dis[T]!=-;
}
int dinic(int x,int f){
int rest=f;
if(x==T) return f;
for(int i=head[x];i;i=e[i].pre){
if(!e[i].f||dis[e[i].v]!=dis[x]+) continue;
int t=dinic(e[i].v,min(rest,e[i].f));
if(!t) dis[e[i].v]=-;
e[i].f-=t;e[i^].f+=t;rest-=t;
}
if(rest==f) dis[x]=-;
return f-rest;
}
int main(){
int Q;scanf("%d",&Q);
while(Q--){
memset(head,,sizeof(head));
memset(s,,sizeof(s));
int sum=;cnt=;
scanf("%d%d",&n,&m);S=;T=n+;
for(int i=;i<=m;i++){
int u,v,minn,maxn;
scanf("%d%d%d%d",&u,&v,&minn,&maxn);
low[i]=minn;s[u]+=minn;s[v]-=minn;
add(u,v,maxn-minn);
}
for(int i=;i<=n;i++)
if(s[i]>) add(i,T,s[i]),sum+=s[i];
else if(s[i]<) add(S,i,-s[i]);
int maxflow=;
while(bfs())
maxflow+=dinic(S,inf);
if(maxflow!=sum) printf("NO\n");
else {
printf("YES\n");
for(int i=;i<=m;i++)
printf("%d\n",low[i]+e[(i<<)^].f);
}
}
return ;
}

Reactor Cooling(ZOJ 2314)的更多相关文章

  1. POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配

    两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...

  2. ZOJ 2314 Reactor Cooling(无源汇上下界网络流)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 题意: 给出每条边流量的上下界,问是否存在可行流,如果存在则输出. ...

  3. zoj 2314 Reactor Cooling (无源汇上下界可行流)

    Reactor Coolinghttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 Time Limit: 5 Seconds ...

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

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

  5. Reactor Cooling(无源汇有上下界网络流)

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

  6. 【有上下界的网络流】ZOJ2341 Reactor Cooling(有上下界可行流)

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

  7. ZOJ2314 Reactor Cooling(有上下界的网络流)

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

  8. 2014 牡丹江现场赛 A.Average Score(zoj 3819) 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5373 题目意思: 有两个class:A 和 B,Bob 在 Clas ...

  9. 2014ACM/ICPC亚洲区域赛牡丹江站现场赛-I ( ZOJ 3827 ) Information Entropy

    Information Entropy Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge Information ...

随机推荐

  1. 第四篇、Swift_Podfile文件配置格式

    # Uncomment this line to define a global platform for your project platform :ios, '9.0' # Comment th ...

  2. node第一天

    一.主要执行的文件命名一般为main.js var aModule =require('./a.js');//相对路径 var aModule =require('a.js');//专门从node_m ...

  3. JS起源

    一.初始JavaScript Mosaic是互联网历史上第一个普遍使用和显示图片的浏览器1993年问世. 后来由于商标权转让,原本的开发团队又开发了Netscape Navigetor网景浏览器,也是 ...

  4. 【转】 bind1st bind2nd的使用

    以前在使用stl的过程中发现bind1st和bind2nd这两个函数,当时不太理解什么意思,今天在网上查了一下相关资料发现竟然很简单,下面我就具体解释一下他们的用法. bind1st和bind2nd函 ...

  5. 【计数】cf938E. Max History

    发现有一种奇怪的方法不能快速预处理? 复习一下常见的凑组合数的套路 You are given an array a of length n. We define fa the following w ...

  6. python 写 组合两两组合

    紧挨着 组合  a b c d  ----> ab ,bc ,cd portList = ['a', 'b', 'c', 'd'] for i, p in enumerate(portList) ...

  7. Linux MySQL 8.0 忘记密码

    不小忘了MySQL的密码,按照书上和网上的内容都没能修改成功,终于在借鉴了多篇文章成功之后找到原因,修改密码成功 修改 MySQL 密码 第一步:关闭 MySQL 进程 systemctl stop ...

  8. mysql面试题:字段中@之前字符相同且大于等于2条的所有记录

    公司发了一张面试题给我,题目如下: 在test数据库中有个flow_user表,找出email字段中@之前字符相同且大于等于2条的所有记录 答案: select substring_index(`em ...

  9. web前后台数据交互的几种方式

    1.利用cookie对象 Cookie是服务器保存在客户端中的一小段数据信息.使用Cookie有一个前提,就是客户端浏览器允许使用Cookie并对此做出相应的设置.一般不赞成使用Cookie. (1) ...

  10. html5定位获取当前位置并在百度地图上显示

    用html5的地理定位功能通过手机定位获取当前位置并在地图上居中显示出来,下面是百度地图API的使用过程,有需要的朋友可以参考下 在开发移动端 web 或者webapp时,使用百度地图 API 的过程 ...