[ZOJ2341]Reactor Cooling解题报告|带上下界的网络流|无源汇的可行流
Reactor Cooling
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 fij, (put fij= 0 if there is no pipe from node i to node j), for each i the following condition must hold:
fi,1+fi,2+...+fi,N = f1,i+f2,i+...+fN,i
Each pipe has some finite capacity, therefore for each i and j connected by the pipe must be fij <= cij where cij 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 lij, thus it must be fij >= lij.
Given cij and lij for all pipes, find the amount fij, satisfying the conditions specified above.
This problem contains multiple test cases!
The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.
The output format consists of N output blocks. There is a blank line between output blocks.
Input
The first line of the input file contains the number N (1 <= N <= 200) - the number of nodes and and M - the number of pipes. The following M lines contain four integer number each - i, j, lij and cij each. There is at most one pipe connecting any two nodes and 0 <= lij <= cij <= 10^5 for all pipes. No pipe connects a node to itself. If there is a pipe from i-th node to j-th, there is no pipe from j-th node to i-th.
Output
On the first line of the output file print YES if there is the way to carry out reactor cooling and NO if there is none. In the first case M integers must follow, k-th number being the amount of liquid flowing by the k-th pipe. Pipes are numbered as they are given in the input file.
第一次在浙大的OJ上做题w
题意大概就是给定一张管道网络以及每一根管道流量的上界和下界
判断是否存在可行流,以及如果存在的话输出一组可行流
感谢NewFarking的文章 (戳这里
做法还是理解了一会儿的呢..
对于一根管道(u,v),设其流量限制为[l,r]
为了简便地解决这个问题我们有一个初步的想法
就是先强制流掉下限流量,然后剩下的给出流量限制之后再随意流
实际上代码也基本是这样实现的
先从u到v连一条容量为r-l的边,也就是自由流
看起来我们将这根管道的下限流确实是流掉了呢
但是整张网络并没有

比如这张图
w到u必须流掉的10单位流量,但从u出发只强制流掉了5单位的流量
还有5单位的流量必须流出去
用什么来强制流出去呢?
答案是从s到u建一条容量为5的边
因为我们最终判断是否存在可行流的条件是s连出的边是否全部满流
那么一旦存在可行解,这5个单位的流量全流出去了,能达到我们的目的
这道题让我们输出一组可行解,我是在Dfs的过程中处理的
UPD.顺便写一写其他几种的建图方法:
有源汇的可行流:转换成无源汇的可行流来做,即从t→s连一条容量为正无穷
无下限的边,整个图就转化成了循环图
有源汇的最大流/有源汇的最小流:拆边的方法太奇怪不好理解
二分t→s的下限即可
program zoj2314;
const maxn = ;maxm = ;
var fa,next,ter,w,rec,flow:array[-..maxm]of longint;
link,dis,opt,inp:array[-..maxn]of longint;
vis:array[-..maxn]of boolean;
n,m,e,tt,test,i,s,t,x,y,l,r:longint; function min(a,b:longint):longint;
begin
if a<b then exit(a) else exit(b);
end; function spfa:boolean;
var head,tail,x,j:longint;
begin
fillchar(vis,sizeof(vis),true);
fillchar(dis,sizeof(dis),);
head:=;tail:=;opt[]:=s;vis[s]:=false;dis[s]:=;
while head<>tail do
begin
head:=(head+) mod maxn;
x:=opt[head];j:=link[x];
while j<> do
begin
if (dis[x]+<dis[ter[j]])and(w[j]>) then
begin
dis[ter[j]]:=dis[x]+;
if vis[ter[j]] then
begin
vis[ter[j]]:=false;
tail:=(tail+) mod maxn;
opt[tail]:=ter[j];
end;
end;
j:=next[j];
end;
vis[x]:=true;
end;
if dis[t]<>dis[t+] then exit(true) else exit(false);
end; function dfs(p,sum:longint):longint;
var tem,j,x:longint;
begin
tem:=;
if p=t then exit(sum);
j:=link[p];
while j<> do
begin
if (dis[ter[j]]=dis[p]+)and(w[j]>) then
begin
x:=dfs(ter[j],min(sum-tem,w[j]));
inc(tem,x);dec(w[j],x);inc(w[rec[j]],x);
// writeln(p,' ',ter[j],' ',fa[j],' ',x);
if rec[j]=j+ then inc(flow[fa[j]],x) else dec(flow[fa[rec[j]]],x);
if tem=sum then exit(sum);
end;
j:=next[j];
end;
exit(tem);
end; procedure add(x,y,z,fat:longint);
begin
// writeln(x,' ',y,' ',z);
inc(e);ter[e]:=y;next[e]:=link[x];link[x]:=e;w[e]:=z;fa[e]:=fat;rec[e]:=e+;
inc(e);ter[e]:=x;next[e]:=link[y];link[y]:=e;w[e]:=;fa[e]:=fat;rec[e]:=e-;
end; function Jud:boolean;
var j:longint;
begin
j:=link[s];
while j<> do
begin
if w[j]> then exit(false);
j:=next[j];
end;
exit(true);
end; procedure Solve;
var i,sum:longint;
begin
sum:=;
while spfa do inc(sum,dfs(s,));
if not Jud then writeln('NO') else
begin
writeln('YES');
for i:= to m do writeln(flow[i]);
end;
writeln;
end; begin
//assign(input,'zoj2314.in');reset(input);
readln(test);
for tt:= to test do
begin
readln;
readln(n,m);
fillchar(inp,sizeof(inp),);
fillchar(link,sizeof(link),);
fillchar(next,sizeof(next),);
e:=;s:=;t:=n+;
for i:= to m do
begin
readln(x,y,l,r);
flow[i]:=l;
dec(inp[x],l);inc(inp[y],l);
add(x,y,r-l,i);
end;
for i:= to n do if inp[i]> then add(s,i,inp[i],) else
if inp[i]< then add(i,t,-inp[i],);
Solve;
end;
end.
[ZOJ2341]Reactor Cooling解题报告|带上下界的网络流|无源汇的可行流的更多相关文章
- ZOJ 2314 Reactor Cooling 带上下界的网络流
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 题意: 给n个点,及m根pipe,每根pipe用来流躺液体的, ...
- sgu 194 Reactor Cooling(有容量上下界的无源无汇可行流)
[题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20757 [题意] 求有容量上下界的无源无汇可行流. [思路] ...
- SGU 194 【带上下界的无源汇的可行流】
题意: 给点数n和边数m. 接下来m条有向边. a b c d 一次代表起点终点,下界上界. 求: 判断是否存在可行流,若存在则输出某可行流.否则输出IMPOSSIBLE 思路: <一种简易的方 ...
- 【HDU 4940】Destroy Transportation system(无源无汇带上下界可行流)
Description Tom is a commander, his task is destroying his enemy’s transportation system. Let’s repr ...
- ZOJ2314 Reactor Cooling(有上下界的网络流)
The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuclear ...
- SGU 194. Reactor Cooling(无源汇有上下界的网络流)
时间限制:0.5s 空间限制:6M 题意: 显然就是求一个无源汇有上下界的网络流的可行流的问题 Solution: 没什么好说的,直接判定可行流,输出就好了 code /* 无汇源有上下界的网络流 * ...
- 【ZOJ2314】Reactor Cooling(有上下界的网络流)
前言 话说有上下界的网络流好像全机房就我一个人会手动滑稽,当然这是不可能的 Solution 其实这道题目就是一道板子题,主要讲解一下怎么做无源无汇的上下界最大流: 算法步骤 1.将每条边转换成0~u ...
- ZOJ 2314 带上下界的可行流
对于无源汇问题,方法有两种. 1 从边的角度来处理. 新建超级源汇, 对于每一条有下界的边,x->y, 建立有向边 超级源->y ,容量为x->y下界,建立有向边 x-> 超级 ...
- BZOJ2150 部落战争 【带上下界最小流】
题目链接 BZOJ2150 题解 复习: 带上下界网络流两种写法: 不建\(T->S\)的\(INF\)的边,即不考虑源汇点,先求出此时超级源汇的最大流,即无源汇下最大的自我调整,再加入该边,求 ...
随机推荐
- hdu5863 cjj's string game
矩阵快速幂 #include<bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MOD = ...
- 【app.js】配置及App函数说明
app.js中的App函数用来注册一个小程序或设置全局变量. App函数: 语法:App(Object) 参数: Object json对象 说明: App函数必须在app.js中调用 ...
- 1107 Social Clusters (30 分)(并查集)
并查集的基本应用 #include<bits/stdc++.h> using namespace std; ; vector<int>vec[N]; int p[N]; con ...
- 可以随着SeekBar滑块滑动显示的Demo
//关于Seek的自定义样式,之前也有总结过,但是,一直做不出随着滑块移动的效果,查询了很多资料终于解决了这个问题,现在把代码写出来有bug的地方 希望大家批评指正. Step 1 :自定义一个Vie ...
- 简单java采集程序一
[目标任务]通过该网站采集全国的手机号码段至数据库表中 [完成过程] 1.初涉正则表达式,学会写简单的正则表达式 2.获取单个网页内容,学会java中基本的IO流 3.将获取数据插入mysql数据库表 ...
- MySQL初识3
随着对MySQL的熟识,今次总结一下MySQL数据库的删除.备份和还原操作 1.数据库的删除: a.删除数据库的命令:drop database dbname; b.删除数据库中的表: 单个表:dro ...
- 团队作业4——第一次项目冲刺(Alpha版本)-第二篇
项目冲刺——第二阶段 度过了敏捷冲刺,各个成员积极汇报各自的工作.好了,着手下一步规划! Mission 团队成员 任务 郭达 实现PHP后台的答题判分查看正确率 刘德培 编写博客 石浩洋 实现 ...
- c语言第五次作业-指针-总结博客
本次作业亮点 1.1整体情况 本次作业主要是对上次的大作业利用指针进行改进,但是大部分同学并没有很好按照老师的要求对大作业进行改进,函数的分装性也做得不够好,由于是初步学习指针,大家在本次的作业改造中 ...
- 获取web服务器路径的方法 getResourceAsStream
1.先获取 serlvetContext对象 2.调用getResourceAsStream 在方法里 "\"表示当前web的根目录 还要拼接上具体的文件路径 ServletC ...
- 【bzoj1458】士兵占领 有上下界最小流
题目描述 有一个M * N的棋盘,有的格子是障碍.现在你要选择一些格子来放置一些士兵,一个格子里最多可以放置一个士兵,障碍格里不能放置士兵.我们称这些士兵占领了整个棋盘当满足第i行至少放置了Li个士兵 ...