SGU 194 Reactor Cooling
http://acm.sgu.ru/problem.php?contest=0&problem=194
题意:m条有向边,有上下界,求最大流。
思路:原图中有u-v low[i],high[i] 建图就是u->v,high[i]-low[i],同时du[u]-=low[i],du[v]+=low[i],然后对于每个点i,如果du[i]>0,那就S->i,du[i],若是du[i]<0那就i->T ,-du[i],然后判断S出去的流是不是满流,不是就无解,否则每条边流量就是基础流量再加上附加流。
啊♂,一开始脑抽了,反向边流量忘记变成0了。。
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#define inf 0x7fffffff
int S,T,nodes;
int id[];
int tot,go[],next[],dn[],first[],flow[];
int dis[],cnt[],op[],ans[],du[],n,m;
int read(){
char ch=getchar();int t=,f=;
while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
void insert(int x,int y,int z,int Id){
tot++;
go[tot]=y;
next[tot]=first[x];
first[x]=tot;
flow[tot]=z;
id[tot]=Id;
}
void add(int x,int y,int z,int Id){
insert(x,y,z,Id);op[tot]=tot+;
insert(y,x,,);op[tot]=tot-;
}
int dfs(int x,int f){
if (x==T) return f;
int mn=nodes,sum=;
for (int i=first[x];i;i=next[i]){
int pur=go[i];
if (flow[i]&&dis[pur]+==dis[x]){
int save=dfs(pur,std::min(f-sum,flow[i]));
sum+=save;
flow[i]-=save;
flow[op[i]]+=save;
if (dis[S]>=nodes||f==sum) return sum;
}
if (flow[i]) mn=std::min(mn,dis[pur]);
}
if (sum==){
cnt[dis[x]]--;
if (cnt[dis[x]]==)
dis[S]=nodes;
else
dis[x]=mn+,cnt[dis[x]]++;
}
return sum;
}
int main(){
while (~scanf("%d%d",&n,&m)){
for (int i=;i<=n+;i++) dis[i]=cnt[i]=first[i]=du[i]=;
tot=;S=;T=n+;nodes=T+;
for (int i=;i<=m;i++){
int u=read(),v=read(),lf=read(),hf=read();
add(u,v,hf-lf,i);
du[u]-=lf;
du[v]+=lf;
dn[i]=lf;
}
for (int i=;i<=n;i++){
if (du[i]>) add(S,i,du[i],);
if (du[i]<) add(i,T,-du[i],);
}
int Ans;
while (dis[S]<nodes) Ans+=dfs(S,inf);
bool flag=true;
for (int i=first[S];i;i=next[i])
if (flow[i]!=){
flag=false;
break;
}
if (!flag) {
puts("NO");
continue;
}else{
puts("YES");
for (int i=;i<=tot;i++) ans[id[i]]=flow[op[i]];
for (int i=;i<=m;i++) printf("%d\n",dn[i]+ans[i]);
}
}
}
SGU 194 Reactor Cooling的更多相关文章
- SGU 194 Reactor Cooling(无源无汇上下界可行流)
Description The terrorist group leaded by a well known international terrorist Ben Bladen is bulidin ...
- SGU 194 Reactor Cooling 无源汇带上下界可行流
Reactor Cooling time limit per test: 0.5 sec. memory limit per test: 65536 KB input: standard output ...
- SGU 194 Reactor Cooling (无源上下界网络流)
The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuclear ...
- 【无源汇上下界最大流】SGU 194 Reactor Cooling
题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=194 题目大意: n个点(n<20000!!!不是200!!!RE了无数次) ...
- sgu 194 Reactor Cooling(有容量上下界的无源无汇可行流)
[题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20757 [题意] 求有容量上下界的无源无汇可行流. [思路] ...
- SGU 194 Reactor Cooling Dinic求解 无源无汇有上下界的可行流
题目链接 题意:有向图中有n(1 <= n <= 200)个点,无自环或者环的节点个数至少为3.给定每条边的最小流量和最大流量,问每条边的可行流量为多少? 思路:一般求解的网络流并不考虑下 ...
- SGU 194. Reactor Cooling(无源汇有上下界的网络流)
时间限制:0.5s 空间限制:6M 题意: 显然就是求一个无源汇有上下界的网络流的可行流的问题 Solution: 没什么好说的,直接判定可行流,输出就好了 code /* 无汇源有上下界的网络流 * ...
- SGU 194 Reactor Cooling ——网络流
[题目分析] 无源汇上下界可行流. 上下界网络流的问题可以参考这里.↓ http://www.cnblogs.com/kane0526/archive/2013/04/05/3001108.html ...
- SGU 194 Reactor Cooling (有容量和下界的可行流)
题意:给定上一个有容量和下界的网络,让你求出一组可行解. 析:先建立一个超级源点 s 和汇点 t ,然后在输入时记录到每个结点的下界的和,建边的时候就建立c - b的最后再建立 s 和 t , 在建立 ...
随机推荐
- Powershell Switch 条件
Powershell Switch 条件 6 21 1月, 2012 在 Powershell tagged Powershell教程/ 分支/ 字符串/ 数字/ 条件by Mooser Lee 本 ...
- Jsvc安装,配置 常规用户使用tomcat的80端口
Jsvc安装 一.下载安装包,地址如下: http://commons.apache.org/proper/commonsdaemon/download_daemon.cgi 二.安装步骤,参考链接 ...
- struct2(六) 为表单添加验证
简介 为表单添加验证 添加校验的方法: 1. first name 不能为null 2. Email address 不能为null 3. age 必须大于18岁 为了在用户提交的时候,能够校验这个表 ...
- c#类和结构体的关系
原文地址:http://www.dnbcw.com/biancheng/c/fvhc81798.html 简介:这是c#类和结构体的关系的详细页面,介绍了和c/c++,有关的知识,谢谢大家的观看!要查 ...
- cocos2dx-lua绑定自定义c++类(一)
本文主要介绍mac上,如何将自定义的c++类,绑定到lua. 1.工具先行 找到 你的cocos2d-x/tools/tolua++,里面文件按类型大致分为: (1)*.pkg:用于定义要绑定的c++ ...
- QQ地图api里的 地址解析函数 看不懂 javascript_百度知道
QQ地图api里的 地址解析函数 看不懂 javascript_百度知道 QQ地图api里的 地址解析函数 看不懂 javascript 2011-09-18 12:18 匿名 ...
- Python安装MySQLdb并连接MySQL数据库
当然了,前提是你已经安装了Python和MySQL.我的Python是2.6版本的. Python2.6的“Set”有点兼容性问题,自己照着改一下: http://sourceforge.net/fo ...
- 讲解版的自动轮播(新手福利)样式和js就不分离了为了看的方便
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- HDU ACM 1078 FatMouse and Cheese 记忆化+DFS
题意:FatMouse在一个N*N方格上找吃的,每一个点(x,y)有一些吃的,FatMouse从(0,0)的出发去找吃的.每次最多走k步,他走过的位置能够吃掉吃的.保证吃的数量在0-100.规定他仅仅 ...
- [RxJS] Getting Input Text with Map
By default, Inputs will push input events into the stream. This lesson shows you how to use map to c ...