sgu194:http://acm.sgu.ru/problem.php?contest=0&problem=194

题意:题目大意:给n个点,及m根pipe,每根pipe用来流躺液体的,单向的,每时每刻每根pipe流进来的物质要等于流出去的物质,要使得m条pipe组成一个循环体,里面流躺物质。并且满足每根pipe一定的流量限制,范围为[Li,Ri].即要满足每时刻流进来的不能超过Ri(最大流问题),同时最小不能低于Li。

题解:题解:。对于每根管子有一个上界容量up和一个下界容量low,我们让这根管子的容量下界变为0,上界为up-low。可是这样做了的话流量就不守恒了,为了再次满足流量守恒,即每个节点"入流=出流”,我们增设一个超级源点st和一个超级终点sd。我们开设一个数组du[]来记录每个节点的流量情况。du[i]=in[i](i节点所有入流下界之和)-out[i](i节点所有出流下界之和)。当du[i]大于0的时候,st到i连一条流量为du[i]的边。当du[i]小于0的时候,i到sd连一条流量为-du[i]的边。最后对(st,sd)求一次最大流即可,如果从源点流出的边都满流了,则就有可行解,否则无解。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#define min(a,b)(a<b?a:b)
#define INF 1000000
using namespace std;
const int MAX=;
struct Node {
int c;
int f;
};
int sx,ex;//sx和ex分别代表源点和汇点
int pre[MAX];
Node map[][];
int n,m;
int du[MAX];
int dx[MAX],ll[MAX],rr[MAX];//记录每条边的流量下界,起点,终点
bool BFS() { //BFS搜索层次网络
memset(pre,,sizeof(pre));
queue< int > Q;
Q.push(sx);
pre[sx]=;
while(!Q.empty()) {
int d=Q.front();
Q.pop();
for(int i=; i<=n+; i++) {
if(!pre[i]&&map[d][i].c-map[d][i].f) {
pre[i]=pre[d]+;
Q.push(i);
}
}
}
return pre[ex]!=;
}
int dinic(int pos,int flow) { //pos是顶点号,flow是当前顶点所能得到的流量,一次dinic只能求出一次增加的流量,
int f=flow;
if(pos==ex)
return flow;
for(int i=; i<=+n; i++) {
if(map[pos][i].c-map[pos][i].f&&pre[pos]+==pre[i]) {
int a=map[pos][i].c-map[pos][i].f;
int t=dinic(i,min(a,flow));
map[pos][i].f+=t;
map[i][pos].f-=t;
flow-=t;
if(flow<=)break;
//我最开始就是这里没弄明白,我不明白为什么要此顶点得到的流量减去改变量;
//答案就在下面的 return f-flow;
}
}
if(f-flow<=)pre[pos]=-;
return f-flow;//其实这里返回给他前一层的就是这个t;因为t在层函数里面都有,所以所过避免重复就写成这样;
}
void slove(){
int sum=;
while(BFS()) {
sum+=dinic(sx,INF);
}
//return sum;
}
int main() {
int u,v,t1,t2;
while(cin>>n>>m) {
memset(du,,sizeof(du));
sx=;
ex=n+;
memset(map,,sizeof(map)) ;
for(int i=;i<=m; i++) {
cin>>u>>v>>t1>>t2;
map[u][v].c+=t2-t1;
du[u]-=t1;
du[v]+=t1;
dx[i]=t1;
ll[i]=u;
rr[i]=v;
}
for(int i=;i<=n;i++){
if(du[i]>)map[][i].c+=du[i];
if(du[i]<)map[i][n+].c+=(-du[i]);
}
slove();
bool flag=false;
for(int i=;i<=n;i++){
if(du[i]>){
if(map[][i].f!=map[][i].c){
flag=true;
break;
} }
}
if(flag)printf("NO\n");
else{
printf("YES\n");
for(int i=;i<=m;i++){
printf("%d\n",map[ll[i]][rr[i]].f+dx[i]);
}
}
}
return ;
}

Reactor Cooling的更多相关文章

  1. ZOJ2314 Reactor Cooling

    Reactor Cooling Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special Judge The terrorist g ...

  2. zoj Reactor Cooling

    Reactor Cooling 无源汇上下界最大流问题. 1.流量平衡. 2.满足上下界 模板题. #include <iostream> #include <queue> # ...

  3. acdream 1211 Reactor Cooling 【边界网络流量 + 输出流量】

    称号:acdream 1211 Reactor Cooling 分类:无汇的有上下界网络流. 题意: 给n个点.及m根pipe,每根pipe用来流躺液体的.单向的.每时每刻每根pipe流进来的物质要等 ...

  4. 【有上下界的网络流】ZOJ2341 Reactor Cooling(有上下界可行流)

     Description The terrorist group leaded by a well known international terrorist Ben Bladen is bulidi ...

  5. ZOJ 1314 Reactor Cooling | 上下界无源汇可行流

    ZOJ 1314 Reactor Cooling | 上下界无源汇可行流 题意 有一个网络,每条边有流量的上界和下界,求一种方案,让里面的流可以循环往复地流动起来. 题解 上下界无源汇可行流的模型: ...

  6. ZOJ 2314 - Reactor Cooling - [无源汇上下界可行流]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 The terrorist group leaded by ...

  7. zoj 2314 Reactor Cooling (无源汇上下界可行流)

    Reactor Coolinghttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 Time Limit: 5 Seconds ...

  8. SGU 194 Reactor Cooling(无源无汇上下界可行流)

    Description The terrorist group leaded by a well known international terrorist Ben Bladen is bulidin ...

  9. 【zoj2314】Reactor Cooling 有上下界可行流

    题目描述 The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuc ...

  10. [ZOJ2341]Reactor Cooling解题报告|带上下界的网络流|无源汇的可行流

    Reactor Cooling The terrorist group leaded by a well known international terrorist Ben Bladen is bul ...

随机推荐

  1. Chapter 5. The Gradle Wrapper 关于gradle wrapper

    Most tools require installation on your computer before you can use them. If the installation is eas ...

  2. 升级mac的java版本

    在OS X EI Capitan下, java版本太低,从oracle官网下载的dmg文件升级一直有问题, 我发现mac下的java环境有三处 #这应该是系统自带java环境,默认/usr/bin/j ...

  3. linux 下ffmpeg和mencoder安装

    ffmpeg和mencoder是进行视频转换和视频抽帧的重要开源工具,支持linux和windows环境下的视频转换和视频抽帧操作.本文章记录在linux这两者工具的安装过程.ffmpeg集成视频编码 ...

  4. 正则表达式工具类,正则表达式封装,Java正则表达式

    正则表达式工具类 正则表达式封装 Java正则表达式 >>>>>>>>>>>>>>>>>>& ...

  5. fsdfasfsa

    http://www.cnblogs.com/daniel206/archive/2008/01/16/1041729.html using System.IO;using System.Net;us ...

  6. 将应用程序中的一些参数写到xml配置文件中

    最近碰到一个问题,需要将程序中的一些基本参数写到xml文件中,虽然网上有好多现成的代码,但是觉得对xml不熟悉,果断就研究了一下.先说一下大体思路吧,我设计了一个用来读取和回填的类,然后定义了一个接口 ...

  7. Visual Studio 2013 RTM 中文语言包官方下载地址发布

    如果你下载的是英文版,你想安装一个中文的visual studio 2013,那么你大可不必重新下载安装visual studio 2013,因为微软提供了Visual Studio 2013 RTM ...

  8. iOS10新增Api详解

    1.SiriKit SiriKit的功能非常强大,支持音频.视频.消息发送接收.搜索照片.预订行程.管理锻炼等等.在用到此服务时,siri会发送Intent对象,里面包括用户的请求和各种数据,可以对这 ...

  9. BearSkill实用方法之UITextField限制输入的字符数量

    原文:http://blog.csdn.net/xiongbaoxr/article/details/51525061      

  10. C#字符串颠倒输出

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...