Zoj 2314 Reactor Cooling(无源汇有上下界可行流)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314
题意:
给n个点,及m根pipe,每根pipe用来流躺液体的,单向的,每时每刻每根pipe流进来的物质要等于流出去的物质,要使得m条pipe组成一个循环体,里面流躺物质。
并且满足每根pipe一定的流量限制,范围为[Li,Ri].即要满足每时刻流进来的不能超过Ri(最大流问题),同时最小不能低于Li。
模板:无源汇有上下界可行流
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<queue>
using namespace std;
const int maxn=;
int sp,tp,cnt=,head[],nxt[maxn],to[maxn],cap[maxn],dis[],low[maxn],def[],m,n;
inline int read(){
int ans=; char last=' ',ch=getchar();
while(ch<'' || ch>'')last=ch,ch=getchar();
while(ch>='' && ch<='')ans=ans*+ch-'',ch=getchar();
if(last=='-')ans=-ans; return ans;
}
inline void add(int u,int v,int p){
nxt[cnt]=head[u],to[cnt]=v,cap[cnt]=p,head[u]=cnt++;
nxt[cnt]=head[v],to[cnt]=u,cap[cnt]=,head[v]=cnt++;
}
inline bool bfs(){
int u,e,v;
queue<int> que;
memset(dis,-,sizeof(dis));
que.push(sp),dis[sp]=;
while(!que.empty()){
u=que.front(),que.pop();
for(int e=head[u];~e;e=nxt[e]){
if(cap[e]>&&dis[v=to[e]]==-){
dis[v]=dis[u]+,que.push(v);
if(v==tp) return true;
}
}
}
return false;
}
inline int dfs(const int &u,const int &flow){
if(u==tp) return flow;
int res=,v,flw;
for(int e=head[u];~e;e=nxt[e]){
if(cap[e]>&&dis[u]<dis[v=to[e]]){
flw=dfs(v,min(cap[e],flow-res));
if(flw==) dis[v]=-;
cap[e]-=flw,cap[e^]+=flw;
res+=flw;
if(res==flow) break;
}
}
return res;
}
inline int dinic(int sp,int tp){
int ans=;
while(bfs()) {
ans+=dfs(sp,<<);
}
return ans;
}
int main(){
int t;
t=read();
while(t--)
{
cnt=;
memset(def,,sizeof(def));
memset(head,-,sizeof(head));
n=read(),m=read();
int s,t,up,down,sum=;
for(int i=;i<=m;i++){
s=read(),t=read(),down=read(),up=read();
add(s,t,up-down);
low[i]=down,def[s]+=down,def[t]-=down;
}
sp=n+,tp=n+;
for(int i=;i<=n;i++){
if(def[i]>) sum+=def[i],add(i,tp,def[i]);
if(def[i]<) add(sp,i,-def[i]);
}
if(dinic(sp,tp)==sum){
cout<<"YES"<<endl;
for(int i=;i<=m;i++){
cout<<cap[((i-)*)^]+low[i]<<endl;
}
}
else cout<<"NO"<<endl;
}
return ;
}
Zoj 2314 Reactor Cooling(无源汇有上下界可行流)的更多相关文章
- ZOJ 2314 Reactor Cooling(无源汇有上下界可行流)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 题目大意: 给n个点,及m根pipe,每根pipe用来流躺 ...
- SGU 194 Reactor Cooling 无源汇带上下界可行流
Reactor Cooling time limit per test: 0.5 sec. memory limit per test: 65536 KB input: standard output ...
- ZOJ 2314 (sgu 194) Reactor Cooling (无源汇有上下界最大流)
题意: 给定n个点和m条边, 每条边有流量上下限[b,c], 求是否存在一种流动方法使得每条边流量在范围内, 而且每个点的流入 = 流出 分析: 无源汇有上下界最大流模板, 记录每个点流的 in 和 ...
- LOJ [#115. 无源汇有上下界可行流](https://loj.ac/problem/115)
#115. 无源汇有上下界可行流 先扔个板子,上下界的东西一点点搞,写在奇怪的合集里面 Code: #include <cstdio> #include <cstring> # ...
- 2018.08.20 loj#115. 无源汇有上下界可行流(模板)
传送门 又get到一个新技能,好兴奋的说啊. 一道无源汇有上下界可行流的模板题. 其实这东西也不难,就是将下界变形而已. 准确来说,就是对于每个点,我们算出会从它那里强制流入与流出的流量,然后与超级源 ...
- [loj#115] 无源汇有上下界可行流 网络流
#115. 无源汇有上下界可行流 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:Special Judge 上传者: 匿名 提交提交记录统计讨论测试数据 题 ...
- loj#115. 无源汇有上下界可行流
\(\color{#0066ff}{ 题目描述 }\) 这是一道模板题. \(n\) 个点,\(m\) 条边,每条边 \(e\) 有一个流量下界 \(\text{lower}(e)\) 和流量上界 \ ...
- 【LOJ115】无源汇有上下界可行流(模板题)
点此看题面 大致题意: 给你每条边的流量上下界,让你判断是否存在可行流.若有,则还需输出一个合法方案. 大致思路 首先,每条边既然有一个流量下界\(lower\),我们就强制它初始流量为\(lower ...
- LibreOJ #115. 无源汇有上下界可行流
二次联通门 : LibreOJ #115. 无源汇有上下界可行流 /* LibreOJ #115. 无源汇有上下界可行流 板子题 我也就会写写板子题了.. */ #include <cstdio ...
随机推荐
- bzoj 4817: [Sdoi2017]树点涂色 LCT+树链剖分+线段树
题目: Bob有一棵n个点的有根树,其中1号点是根节点.Bob在每个点上涂了颜色,并且每个点上的颜色不同. 定义一条路径的权值是:这条路径上的点(包括起点和终点)共有多少种不同的颜色. Bob可能会进 ...
- 学习大牛笔记nginx + gunicorn + supervisor
安装 gunicorn pip install gunicorn pip 是一个重要的工具,python 用来管理包.还有一个最佳生产就是每次使用 pip 安装的库,都写入一个 requirement ...
- Gson小记
Gson过滤字段,只要在字段前面添加“transient”关键字即可:之前就是因为Channel字段序列化的时候导致了stack over异常.
- Git 权限控制
除了 Git 命令,权限控制也是 Git 中极为重要的组成部分,本文主要介绍 GitLab 系统提供的最常用的权限控制功能. 一.分配成员角色 首先来了解下,Git 中的五种角色: 每一种角色所拥有的 ...
- 更改Linux时区的两种方法
在Azure上的Linux虚拟机启动后默认是UTC的时区.对很多应用要记录时间戳非常的不方便. 本文将介绍两种更改Linux时间戳的方法,供大家参考. 1.修改/etc/localtime文件 控制系 ...
- 利用SharedRegion实现核间共享
导入SharedRegion模块 SharedRegion模块是一个共享区域,特别是对于多处理器环境下,SharedRegion模块就是用于让一个内存区域能被不同处理器共享并操作.这个模块会给每个处理 ...
- HDU1698(线段树入门题)
Just a Hook Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descrip ...
- Java 的 Tuple 元组数据类型
元组类型,即 Tuple 常在脚本语言中出现,例如 Scala 的 ("Unmi", "china@qq.com", "blahbla"). ...
- JAVA 1.7并发之Fork/Join框架
在之前的博文里有说过executor框架,其实Fork/Join就是继承executor的升级版啦 executor用于创建一个线程池,但是需要手动的添加任务,如果需要将大型任务分治,显然比较麻烦 而 ...
- 一 Optional
从Java8 引入的一个很有趣的特性是Optional类.Optional类主要解决的问题是臭名昭著的空指针异常(NullPointerException). 一: 创建Optional对象: ...