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(无源汇有上下界可行流)的更多相关文章

  1. ZOJ 2314 Reactor Cooling(无源汇有上下界可行流)

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

  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. LOJ [#115. 无源汇有上下界可行流](https://loj.ac/problem/115)

    #115. 无源汇有上下界可行流 先扔个板子,上下界的东西一点点搞,写在奇怪的合集里面 Code: #include <cstdio> #include <cstring> # ...

  5. 2018.08.20 loj#115. 无源汇有上下界可行流(模板)

    传送门 又get到一个新技能,好兴奋的说啊. 一道无源汇有上下界可行流的模板题. 其实这东西也不难,就是将下界变形而已. 准确来说,就是对于每个点,我们算出会从它那里强制流入与流出的流量,然后与超级源 ...

  6. [loj#115] 无源汇有上下界可行流 网络流

    #115. 无源汇有上下界可行流 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:Special Judge 上传者: 匿名 提交提交记录统计讨论测试数据   题 ...

  7. loj#115. 无源汇有上下界可行流

    \(\color{#0066ff}{ 题目描述 }\) 这是一道模板题. \(n\) 个点,\(m\) 条边,每条边 \(e\) 有一个流量下界 \(\text{lower}(e)\) 和流量上界 \ ...

  8. 【LOJ115】无源汇有上下界可行流(模板题)

    点此看题面 大致题意: 给你每条边的流量上下界,让你判断是否存在可行流.若有,则还需输出一个合法方案. 大致思路 首先,每条边既然有一个流量下界\(lower\),我们就强制它初始流量为\(lower ...

  9. LibreOJ #115. 无源汇有上下界可行流

    二次联通门 : LibreOJ #115. 无源汇有上下界可行流 /* LibreOJ #115. 无源汇有上下界可行流 板子题 我也就会写写板子题了.. */ #include <cstdio ...

随机推荐

  1. POJ1904 King's Quest

    King's Quest Language:Default King's Quest Time Limit: 15000MS Memory Limit: 65536K Total Submission ...

  2. 标准模板库(STL)学习指南之vector向量

    vector – 一.  vector可以模拟动态数组 – 二.  vector的元素可以是任意类型T,但必须具备赋值和拷贝能力(具有public 拷贝构造函数和重载的赋值操作符) 三.必须包含的头文 ...

  3. maven的配置文件取不同版本

    1. 两个地方需要配置首先是要定义配置源,dev/test/prod对应的配置源需要指定:这是灵活的,可变的:其次要定义配置文件,该配置文件里面的内容采用占位符的方式来编制,在编译打包的过程中要动态根 ...

  4. C#SqlDataReader的用法

    string sqljn = "select [序号],[品名],[电压等级],[单位],[型号],[规格],[红本价格] FROM [book].[dbo].[View_wjprice]& ...

  5. 【转】 Pro Android学习笔记(六三):Preferences(7):代码控制首选项

    [-] 代码实现preference 利用preference保存状态 DialogPreference 代码实现preference View可以不通过xml进行设置,有代码直接进行设置,首选项pr ...

  6. ES6学习之Class

    一.定义类(ES6的类,完全可以看做是构造函数的另一种写法) class Greet { constructor(x, y) { this.x = x; this.y = y; } sayHello( ...

  7. python fabric的安装与使用

    背景:fabric主要执行远程的shell命令,包括文件的上传.下载,以及提示用户输入等辅助其它功能. 测试系统:ubuntu16 要求:python //系统有自带,ubuntu16 通常自带pyt ...

  8. badblocks 检查磁盘损坏的区块

    Linux badblocks命令用于检查磁盘装置中损坏的区块. 语法: badblocks [-svw][-b <区块大小>][-o <输出文件>][磁盘装置][磁盘区块数] ...

  9. C++经典题目:有n个整数,使前面各数顺序向后移动m个位置

    问题描述: 有n个整数,使前面各数顺序向后移动m个位置,最后m个数变成最前m个数. 程序代码: #include<iostream> #define MAXLEN 200 using na ...

  10. Python通过调用windows命令行处理sam文件

    Python通过调用windows命令行处理sam文件 以samtools软件为例 一.下载或者索取得到windows版本的samtools软件,解压后如下: 进入文件内部,有如下几个文件: 二.将s ...