SGU 194 Reactor Cooling (无源上下界网络流)
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 f ij, (put f ij = 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 f ij ≤ c ij where c ij 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 l ij, thus it must be f ij ≥ l ij.
Given c ij and l ij for all pipes, find the amount f ij, satisfying the conditions specified above.
4 6
1 2 1 2
2 3 1 2
3 4 1 2
4 1 1 2
1 3 1 2
4 2 1 2
Test #2
4 6
1 2 1 3
2 3 1 3
3 4 1 3
4 1 1 3
1 3 1 3
4 2 1 3
NO
Test #2
YES
1
2
3
2
1
1
#include <bits/stdc++.h> using namespace std;
const int maxn = ;
const int inf = 0x3f3f3f3f;
struct Edge
{
int from,to,cap,flow;
Edge (int f,int t,int c,int fl)
{
from=f,to=t,cap=c,flow=fl;
}
};
struct Dinic
{
int n,m,s,t;
vector <Edge> edge;
vector <int> G[maxn];//存图
bool vis[maxn];//标记每点是否vis过
int cur[maxn];//当前弧优化
int dep[maxn];//标记深度
void init(int n,int s,int t)//初始化
{
this->n=n;this->s=s;this->t=t;
edge.clear();
for (int i=;i<n;++i) G[i].clear();
}
void addedge (int from,int to,int cap)//加边,单向边
{
edge.push_back(Edge(from,to,cap,));
edge.push_back(Edge(to,from,,));
m=edge.size();
G[from].push_back(m-);
G[to].push_back(m-);
}
bool bfs ()
{
queue<int> q;
while (!q.empty()) q.pop();
memset(vis,false,sizeof vis);
vis[s]=true;
dep[s]=;
q.push(s);
while (!q.empty()){
int u=q.front();
//printf("%d\n",u);
q.pop();
for (int i=;i<G[u].size();++i){
Edge e=edge[G[u][i]];
int v=e.to;
if (!vis[v]&&e.cap>e.flow){
vis[v]=true;
dep[v]=dep[u]+;
q.push(v);
}
}
}
return vis[t];
}
int dfs (int x,int mi)
{
if (x==t||mi==) return mi;
int flow=,f;
for (int &i=cur[x];i<G[x].size();++i){
Edge &e=edge[G[x][i]];
int y=e.to;
if (dep[y]==dep[x]+&&(f=dfs(y,min(mi,e.cap-e.flow)))>){
e.flow+=f;
edge[G[x][i]^].flow-=f;
flow+=f;
mi-=f;
if (mi==) break;
}
}
return flow;
}
int max_flow ()
{
int ans = ;
while (bfs()){
memset(cur,,sizeof cur);
ans+=dfs(s,inf);
}
return ans;
}
}dinic;
int full_flow;
int n,m;
int id[maxn];
int low[maxn];
int main()
{
//freopen("de.txt","r",stdin);
while (~scanf("%d%d",&n,&m)){
full_flow = ;
int src = ,dst = n+;
dinic.init(maxn,src,dst);
for (int i=;i<=m;++i){
int u,v,l,r;
scanf("%d%d%d%d",&u,&v,&l,&r);
//printf("%d %d %d %d\n",u,v,l,r);
full_flow+=l;
low[i]=l;
dinic.addedge(u,v,r-l);
id[i] = dinic.edge.size()-;
//printf("%d %d %d\n",dinic.edge[id[i]].from,dinic.edge[id[i]].to,dinic.edge[id[i]].cap);
dinic.addedge(src,v,l);
dinic.addedge(u,dst,l);
}
if (dinic.max_flow()!=full_flow){
printf("NO\n");
}
else{
printf("YES\n");
for (int i=;i<=m;++i){
printf("%d\n",low[i]+dinic.edge[id[i]].flow);
}
}
}
return ;
}
SGU 194 Reactor Cooling (无源上下界网络流)的更多相关文章
- SGU 194. Reactor Cooling(无源汇有上下界的网络流)
时间限制:0.5s 空间限制:6M 题意: 显然就是求一个无源汇有上下界的网络流的可行流的问题 Solution: 没什么好说的,直接判定可行流,输出就好了 code /* 无汇源有上下界的网络流 * ...
- SGU 194 Reactor Cooling 无源汇带上下界可行流
Reactor Cooling time limit per test: 0.5 sec. memory limit per test: 65536 KB input: standard output ...
- ZOJ 2314 (sgu 194) Reactor Cooling (无源汇有上下界最大流)
题意: 给定n个点和m条边, 每条边有流量上下限[b,c], 求是否存在一种流动方法使得每条边流量在范围内, 而且每个点的流入 = 流出 分析: 无源汇有上下界最大流模板, 记录每个点流的 in 和 ...
- SGU 194 Reactor Cooling ——网络流
[题目分析] 无源汇上下界可行流. 上下界网络流的问题可以参考这里.↓ http://www.cnblogs.com/kane0526/archive/2013/04/05/3001108.html ...
- 【zoj2314】Reactor Cooling 有上下界可行流
题目描述 The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuc ...
- 【无源汇上下界最大流】SGU 194 Reactor Cooling
题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=194 题目大意: n个点(n<20000!!!不是200!!!RE了无数次) ...
- SGU 194 Reactor Cooling(无源无汇上下界可行流)
Description The terrorist group leaded by a well known international terrorist Ben Bladen is bulidin ...
- sgu 194 Reactor Cooling(有容量上下界的无源无汇可行流)
[题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20757 [题意] 求有容量上下界的无源无汇可行流. [思路] ...
- ZOJ 2314 Reactor Cooling 带上下界的网络流
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 题意: 给n个点,及m根pipe,每根pipe用来流躺液体的, ...
随机推荐
- 像计算机科学家一样思考python-第2章 变量、表达式和语句
感想: 1.程序出现语义错误时,画状态图是一个很好的调试办法.打印出关键变量在不同代码处理后值的变化,就能发现问题的蛛丝马迹. 2.每当学习新语言特性时,都应当在交互模式中进行尝试,并故意犯下错误,看 ...
- Python变量和字符串详解
Python变量和字符串详解 几个月前,我开始学习个人形象管理,从发型.妆容.服饰到仪表仪态,都开始做全新改造,在塑造个人风格时,最基础的是先了解自己属于哪种风格,然后找到参考对象去模仿,可以是自己欣 ...
- poj3669 Meteor Shower (宽度优先搜索)
Description - 题目描述 Bessie听说有场史无前例的流星雨即将来临:有谶言:陨星将落,徒留灰烬.为保生机,她誓将找寻安全之所(永避星坠之地).目前她正在平面坐标系的原点放牧,打算在群星 ...
- Easyui表格显示日期格式错误
问题 如下图: 解决办法: 以Sql Server 2008为例,在执行查询时,把“采购日期”字段由datetime转换为string,前端以string类型显示.
- 排序算法三:堆排序(Heapsort)
堆排序(Heapsort)是一种利用数据结构中的堆进行排序的算法,分为构建初始堆,减小堆的元素个数,调整堆共3步. (一)算法实现 protected void sort(int[] toSort) ...
- Hibernate异常:IllegalArgumentException
异常信息: java.lang.IllegalArgumentException: attempt to create delete event with null entity at org.hib ...
- python开发之路-day01
1.Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为A ...
- Redis数据库-基础篇
Redis Redis是一个开源的,先进的key-value存储. 它通常被称为数据结构服务器,因为键可以包含字符串,哈希,链表,集合和有序集合. Redis 简介 Redis 是完全开源免费的,遵守 ...
- 2019 Multi-University Training Contest 1 - 1004 - Vacation - 二分 - 思维
http://acm.hdu.edu.cn/showproblem.php?pid=6581 一开始想了好几个假算法.但是启发了一下潘哥,假如时间知道的话就可以从头开始确定各个车的位置.那么直接 \( ...
- spring 配置属性细节
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/qilixiang012/article/details/28233811 概要(红色为上一篇所讲,蓝 ...