zoj2314(上下界网络流)
来源:互联网 发布:网络营业执照 淘宝 编辑:程序博客网 时间:2024/05/20 07:33
Description
The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuclear reactor to produce plutonium for the nuclear bomb they are planning to create. Being the wicked computer genius of this group, you are responsible for developing the cooling system for the reactor.
The cooling system of the reactor consists of the number of pipes that special cooling liquid flows by. Pipes are connected at special points, called nodes, each pipe has the starting node and the end point. The liquid must flow by the pipe from its start point to its end point and not in the opposite direction.
Let the nodes be numbered from 1 to N . The cooling system must be designed so that the liquid is circulating by the pipes and the amount of the liquid coming to each node (in the unit of time) is equal to the amount of liquid leaving the node. That is, if we designate the amount of liquid going by the pipe from i-th node to j -th as fi,j, (put fi,j = 0 if there is no pipe from node i to node j ), for each i the following condition must hold:
Each pipe has some finite capacity, therefore for each i and j connected by the pipe must be fi,j ≤ ci,j where ci,j is the capacity of the pipe. To provide sufficient cooling, the amount of the liquid flowing by the pipe going from i-th to j -th nodes must be at least li,j , thus it must be fi,j ≥ li,j. Given ci,j and li,j for all pipes, find the amount fi,j, satisfying the conditions specified above
Input
Output
Sample Input
4 61 2 1 22 3 1 23 4 1 24 1 1 21 3 1 24 2 1 24 61 2 1 32 3 1 33 4 1 34 1 1 31 3 1 34 2 1 3
Sample Output
NOYES123211
算法:
重新构图如下:
(1)在原网络的基础上新增源点和汇点s,t,构造出新的只有上界的网络。
(2)对于原网络中的每条弧(u,v),在新网络中添加一条s->v 的容量为low[u][v]的弧,一条u->t 的容量为low[u][v]的弧,一条u->v的容量为up[u][v]-low[u][v] 的弧。
在重新构造的网络中,做s->t的最大流,如果网络流满流,则原网络存在可行的循环流。原图中每一条弧(u,v)对应的流量为新网络中(u,v)的流量加上low[u][v]。
这题是明显的模板题。
#include <iostream>#include <stdio.h>#include <stdlib.h>#include<string.h>#include<algorithm>#include<math.h>#include<queue>#include<iomanip>using namespace std;typedef long long ll;const int oo=1e9;/**oo 表示无穷大*/const int mm=200000;/**mm 表示边的最大数量,记住要是原图的两倍,在加边的时候都是双向的*/const int mn=210;/**mn 表示点的最大数量*/int node,src,dest,edge;/**node 表示节点数,src 表示源点,dest 表示汇点,edge 统计边数*/int ver[mm],flow[mm],nex[mm];int head[mn],work[mn],dis[mn],q[mn];void prepare(int _node, int _src,int _dest){ node=_node,src=_src,dest=_dest; for(int i=0; i<=node; ++i)head[i]=-1; edge=0;}void addedge( int u, int v, int c){ ver[edge]=v,flow[edge]=c,nex[edge]=head[u],head[u]=edge++; ver[edge]=u,flow[edge]=0,nex[edge]=head[v],head[v]=edge++;}bool Dinic_bfs(){ int i,u,v,l,r=0; for(i=0; i<node; ++i)dis[i]=-1; dis[q[r++]=src]=0; for(l=0; l<r; ++l) for(i=head[u=q[l]]; i>=0; i=nex[i]) if(flow[i]&&dis[v=ver[i]]<0) { dis[q[r++]=v]=dis[u]+1; if(v==dest) return 1; } return 0;}int Dinic_dfs( int u, int exp){ if(u==dest) return exp; for(int &i=work[u],v,tmp; i>=0; i=nex[i]) if(flow[i]&&dis[v=ver[i]]==dis[u]+1&&(tmp=Dinic_dfs(v,min(exp,flow[i])))>0) { flow[i]-=tmp; flow[i^1]+=tmp; return tmp; } return 0;}int Dinic_flow(){ int i,ret=0,delta; while(Dinic_bfs()) { for(i=0; i<node; ++i)work[i]=head[i]; while((delta=Dinic_dfs(src,oo)))ret+=delta; } return ret;}int low[20000],tu[20000];int main(){ int n,m; while(~scanf("%d%d",&n,&m)) { prepare(n+2,0,n+1); int s=0,bj=0; while(m--) { int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d); addedge(0,b,c); addedge(a,n+1,c); low[bj]=c; tu[bj++]=edge; addedge(a,b,d-c); s+=c; } if(Dinic_flow()==s) { printf("YES\n"); for(int i=0; i<bj; i++) printf("%d\n",flow[tu[i]^1]+low[i]); } else puts("NO"); } return 0;}
- zoj2314(上下界网络流)
- 【上下界网络流】ZOJ2314 Reactor Cooling
- ZOJ2314 Reactor Cooling (有上下界的网络流)
- zoj2314 Reactor Cooling --- 上下界可行流
- 有上下界最大流初步zoj2314
- [ZOJ2314]/[SGU194] Reactor Cooling 无源汇有上下界网络流
- zoj2314 Reactor Cooling (无源汇的有上下界的最大流)
- ZOJ2314 Reactor Cooling(无源汇上下界可行流)
- 【无源汇上下界可行流】ZOJ2314[Reactor Cooling]题解
- [ZOJ2314]Reactor Cooling(无源汇有上下界的可行流)
- 上下界网络流
- 上下界网络流
- 上下界网络流
- 上下界网络流
- 上下界网络流
- 上下界网络流
- 上下界网络流
- 上下界网络流
- Storm数据流模型的分析及讨论
- android事件分发
- imageclassification 第二节 KNN
- MyEclipse的html/JSP编辑器添加代码自动提示
- 素数路径 Prime Distance On Tree 点分治+FFT
- zoj2314(上下界网络流)
- LDA的介绍
- 试题锦集
- 虚基类与虚拟继承
- iOS开发笔记:实现对手机号、邮箱输入格式的判断(正则表达式)
- Intellij idea 和myeclipse的最常用快捷键
- 自动代码规范检查工具Checkstyle
- Makefile基本用法
- Java中的排序方法(冒泡排序 和 选择排序)