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 ...
随机推荐
- UVA11059 - Maximum Product
1.题目名称 Maximum Product 2.题目地址 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemi ...
- bzoj 3881: [Coci2015]Divljak AC自动机
题目大意: http://www.lydsy.com/JudgeOnline/problem.php?id=3881 题解: 这道题我想出了三种做法,不过只有最后一种能过. 第一种: 首先我们把所有的 ...
- GCC生成动态库
main.c #include <stdio.h> void hello(void); int main(int argc, char ** argv) { printf("Th ...
- Framework配置错误
转自:http://blog.csdn.net/ked/article/details/25052955 VS2012命令提示符无法使用的解决方法 打开VS2012命令提示符时报错“ERROR: Ca ...
- CentOS 7 rsync+inotify实现实时同步
测试环境如下: inotify-slave IP : 172.16.0.222 inotify-master IP : 172.16.0.233 对两台机的要求: 安装依赖包gcc: yum inst ...
- 15、Linux 文件属性和测试( chgrp,chown,chmod和-e -f -d -s
一.更改文件属性 1.chgrp:更改文件属组 语法: chgrp [-R] 属组名文件名 参数选项 -R:递归更改文件属组,就是在更改某个目录文件的属组时,如果加上-R的参数,那么该目录下的所有文件 ...
- range分表
按主键范围进行分表,假设当前主键的最大值为5000,把数据拆成5等份 1-1000:是5000的第1个范围,把该范围的数据作为一张表 1001-2000:是5000的第2个范围,把该范围的数据作为一张 ...
- 以后尽量不用cin、cout啦
cout输出有问题(对于double,不同OJ处理的结果不一样),cin读入机制较scanf繁琐.慢!!!!!!!!
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings (容斥原理)
题目链接 Description Yaroslav thinks that two strings s and w, consisting of digits and having length n ...
- 《Linux内核设计与实现》读书笔记(二)- 内核开发的准备
在尝试内核开发之前,需要对内核有个整体的了解. 主要内容: 获取内核源码 内核源码的结构 编译内核的方法 内核开发的特点 1. 获取内核源码 内核是开源的,所有获取源码特别方便,参照以下的网址,可以通 ...