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. 【Lintcode】364.Trapping Rain Water II

    题目: Given n x m non-negative integers representing an elevation map 2d where the area of each cell i ...

  2. Navicat生成数据库结构同步SQL

    作为一个苦逼的技术男,在做开发的时候经常会遇见程序版本升级,数据库结构变化.我们需要一个快捷的方式让客户尽快从旧版本数据库结构更新至新版本数据库结构.如果每做一次改动我们就记录一下当然是好事,但是万一 ...

  3. 【转】 Pro Android学习笔记(四二):Fragment(7):切换效果

    目录(?)[-] 利用setTransition 利用setCustomAnimations 通过ObjectAnimator自定义动态效果 程序代码的编写 利用fragment transactio ...

  4. hdu 5600 N bulbs 想法+奇偶讨论

    http://acm.hdu.edu.cn/showproblem.php?pid=5600 本文重在分析该题目的思路,代码极其短,但是想到这个题目的思路却是挺复杂的过程. 思路 自己拿到题目也想到了 ...

  5. java笔试(2)

  6. Random获取不重复随机数

    Random R = new Random(Guid.NewGuid().GetHashCode());            int i = R.Next(9999);

  7. js中Function方法

    function.apply(thisArg,argArray) apply方法调用function,传递一个会绑定到this上的对象和一个可选的数组作为参数. apply方法被用在apply调用模式 ...

  8. day01_虚拟机与主机之间ip配置

       虚拟机1: centos_ node1 虚拟机2:centos_node2 宿主主机虚拟机ip配置: vmnet1 来自为知笔记(Wiz)

  9. 8、scala面向对象编程之Trait

    一.Trait基础 1.将trait作为接口使用 // Scala中的Triat是一种特殊的概念 // 首先我们可以将Trait作为接口来使用,此时的Triat就与Java中的接口非常类似 // 在t ...

  10. java File基本操作,以及递归遍历文件夹

    java 的文件操作,相对来说是比较重要的,无论是编写CS还是BS程序,都避免不了要与文件打交道,例如读写配置文件等.虽然现在很多框架都直接帮你做好了这一步! java.io.File 底层是调用与c ...