/*
题意:无源无汇,并且每条边的容量有上下界限的网络流问题!既然无源无汇,那么素有的节点都应该满足“入流==出流”!
输出每一条边的流量,使得满足上面的条件。(如果u->v有流量,那么v->u就不会有流量) 思路:如果增加了源点s和汇点t,对于u->v(下限为l, 上限为f) 将这一条边拆成3条,s->v(容量为l), u->v(容量为f-l)
u->t(容量为l)这样就变成了每一个点的流入或者流出的流量至少是b!然后从s->t走一遍最大流,如果所有的附件边都已经
满载,则就是所有s->v的边和u->t的边(或者只判断其中一者就可以),那么就存在答案!
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
#define N 205
#define M 500000
using namespace std; struct EDGE{
int v, cap, tot, nt, b;
EDGE(){};
EDGE(int v, int cap, int nt, int b) : v(v), cap(cap), nt(nt), b(b), tot(cap){}
}; EDGE edge[M];
int n, m;
int first[N];
int pre[N], d[N];
int sz;
int s, t;
int full, fout; void addEdge(int u, int v, int b, int cap){
edge[sz] = (EDGE(v, cap, first[u],b));
first[u] = sz++;
edge[sz] = (EDGE(u, , first[v], ));
first[v] = sz++; edge[sz] = (EDGE(v, b, first[s], ));
first[s] = sz++;
edge[sz] = (EDGE(s, , first[v], ));
first[v] = sz++; edge[sz] = (EDGE(t, b, first[u], ));
full += b;
first[u] = sz++;
edge[sz] = (EDGE(u, , first[t], ));
first[t] = sz++;
} bool bfs(){
queue<int>q;
memset(d, , sizeof(d));
d[s] = ;
q.push(s);
while(!q.empty()){
int u = q.front(); q.pop();
for(int i = first[u]; ~i; i = edge[i].nt){
int v = edge[i].v;
if(!d[v] && edge[i].cap >){
d[v] = d[u] + ;
q.push(v);
}
}
}
if(d[t] == ) return false;
return true;
} int dfs(int u, int totf){
int ff;
if( u == t) return totf;
int flow = ;
for(int i = first[u]; ~i && totf > flow; i = edge[i].nt){
int v = edge[i].v;
int cap = edge[i].cap;
//流入u节点的当前总的流量为totf,可以得到 u->v1, u->v2, u->v3....这些路径上的最大流的和为flow+=f(u->vi)
//f(u->vi)表示u节点沿着vi节点方向的路径上的最大流;如果u->vi+1的容量为wi+1,那么u->vi+1所允许流过的最大
//的流量就是 min(totf - cost, wi+1)了!
if(d[v] == d[u] + && cap > ){
ff = dfs(v, min(totf - flow, cap));
if(ff){
edge[i].cap -= ff;
edge[i^].cap += ff;
flow += ff;
}
else
d[v] = -;//表示v这个点无法在继续增广下去了
}
}
return flow;//返回从u节点向外流出的最大流量!
} bool Dinic(){
while(bfs())
fout += dfs(, INF);//这一块没想到写成while(dfs())会超时.... if( fout != full) return false;
return true;
} int main(){ scanf("%d%d", &n, &m);
memset(first, -, sizeof(first));
sz = ;
fout = full = ;
s = ; t = n+;
int u, v, l, f;
for(int i = ; i <= m; ++i){
scanf("%d%d%d%d", &u, &v, &l, &f);
addEdge(u, v, l, f-l);
}
if(!Dinic()){
printf("NO\n");
return ;
}
printf("YES\n");
for(int i = ; i <= m; ++i){
int j = (i-)*;
printf("%d\n", edge[j].tot - edge[j].cap + edge[j].b);//输出这条边实际流过的流量+下限
} return ;
}

AC_Dream 1211 Reactor Cooling的更多相关文章

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

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

  2. [ACdream 1211 Reactor Cooling]无源无汇有上下界的可行流

    题意:无源无汇有上下界的可行流 模型 思路:首先将所有边的容量设为上界减去下界,然后对一个点i,设i的所有入边的下界和为to[i],所有出边的下界和为from[i],令它们的差为dif[i]=to[i ...

  3. ZOJ2314 Reactor Cooling

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

  4. zoj Reactor Cooling

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. jq滚动监听-导航滚动

    github地址:https://github.com/yutaogege/jquery.nav.js 代码: <!DOCTYPE html> <html> <head& ...

  2. Log4cpp介绍及使用

    Log4cpp是一个开源的C++类库,它提供了在C++程序中使用日志和跟踪调试的功能.使用log4cpp,可以很便利地将日志或者跟踪调试信息写入字符流.内存字符串队列.文件.回滚文件.调试器.Wind ...

  3. NMAP 基础教程

    原文地址: http://drops.wooyun.org/tips/2002 0x00 nmap 介绍 Nmap  (网络映射器)是由 Gordon Lyon设计,用来探测计算机网络上的主机和服务的 ...

  4. sqlserver内存释放心得

    SQL Server 2008 或者R2的默认内存分配是2147483647MB, 差不多算是无穷大,对于系统内存的管理策略是有多少占多少.SQLserver会把所有处理过的SQL操作缓存在内存里,这 ...

  5. .net下BerkeleyDB操作封装C#版(附单元测试)

        using System; using System.Collections.Generic; using System.IO; using System.Linq; using System ...

  6. 那些在学习iOS开发前就应该知道的事(part 2)

    英文原文:Things I wish I had known before starting iOS development—Part 2 http://www.cocoachina.com/ios/ ...

  7. 《STL系列》之map原理及实现

    上一篇文章<STL系列>之vector原理及实现,介绍了vector的原理及实现,这篇文章介绍map的原理及实现.STL实现源码下载.STL中map的实现是基于RBTree的,我在实现的时 ...

  8. 新建一个Activity

    如果只是新建一个class,还得自己添加XML,好不麻烦: eclipse里可以直接new other Andriod activity,ADT还是很强发滴.哈哈.

  9. Ay.Framework.WPF 2.0建立项目到底有多快

    2015-3-31 今天我已经优化了很多地方,让客户使用起来几乎是傻瓜式使用了,废话不多说,我们开始吧. 默认的我提供了一些图片,但是也只占用了8M多,2.0版本目前总共有45M左右大小,毕竟包含了f ...

  10. NuGet学习笔记(转)

    NuGet学习笔记(1)——初识NuGet及快速安装使用 http://kb.cnblogs.com/page/143190/ 1. NuGet是什么? NuGet is a Visual Studi ...