题意: 给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. macbook pro开机键盘键盘和触摸板没反应问题

    今天遇到开机键盘和触摸板没反应的问题,打电话给售后,他叫我插一个usb外置键盘,开机时按shift+alt+control+电源键开机,突然发现可以了,这bug我也是醉了

  2. 项目10.2-企业级自动化运维工具---puppet详解

    1.认识puppet 1.1 引入 puppet是什么,咱们先不用专业的名词解释它,咱们先描述一些工作场景,看明白这些工作场景,自然会知道puppet是什么. (1)场景一: 管理员想要在100台服务 ...

  3. Linux监控一之Nagios的安装与配置

    一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报 ...

  4. k8s的认证和service account简述

    k8s的认证: 与API server通信的客户端大致有两类:  1.集群客户端工具(kubectl.kubeadm.kubelet等)  2.集群内pod. 任何客户端访问k8s时的过程:  1.认 ...

  5. 虚拟机中配置SQL SERVER2008R2远程访问

    VM虚拟机中配置数据库访问 选择虚拟机设置--硬件--网络适配器,选择桥接模式:直接连接物理网络 不可选用主机模式(与主机共享专用网络) 数据库远程配置,转自:http://jingyan.baidu ...

  6. 动态规划:HDU2159-FATE(二维费用的背包问题)

    FATE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  7. [转载]C#中使用ADO.NET连接SQL Server数据库,自动增长字段用作主键,处理事务时的基本方法

    问题描述: 假设在数据库中存在以下两张数据表: User表,存放用户的基本信息,基本结构如下所示:   类型 说明 ID_User int 自动增长字段,用作该表的主键 UserName varcha ...

  8. 常用的一些api

    发送手机短信 // 发送短信给安全号码 SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phon ...

  9. 4、CSS基础part-2

    1.background-1 ①设置background-image ②设置background-attachment为fixed 可以声明图像相对于可视区是固定的(fixed),因此不会受到滚动的影 ...

  10. 【Candy】cpp

    题目: There are N children standing in a line. Each child is assigned a rating value. You are giving c ...