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的更多相关文章

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

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

  2. SGU 194 Reactor Cooling 无源汇带上下界可行流

    Reactor Cooling time limit per test: 0.5 sec. memory limit per test: 65536 KB input: standard output ...

  3. SGU 194 Reactor Cooling (无源上下界网络流)

    The terrorist group leaded by a well known international terrorist Ben Bladen is buliding a nuclear ...

  4. 【无源汇上下界最大流】SGU 194 Reactor Cooling

    题目链接: http://acm.sgu.ru/problem.php?contest=0&problem=194 题目大意: n个点(n<20000!!!不是200!!!RE了无数次) ...

  5. sgu 194 Reactor Cooling(有容量上下界的无源无汇可行流)

    [题目链接] http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20757 [题意] 求有容量上下界的无源无汇可行流. [思路] ...

  6. SGU 194 Reactor Cooling Dinic求解 无源无汇有上下界的可行流

    题目链接 题意:有向图中有n(1 <= n <= 200)个点,无自环或者环的节点个数至少为3.给定每条边的最小流量和最大流量,问每条边的可行流量为多少? 思路:一般求解的网络流并不考虑下 ...

  7. SGU 194. Reactor Cooling(无源汇有上下界的网络流)

    时间限制:0.5s 空间限制:6M 题意: 显然就是求一个无源汇有上下界的网络流的可行流的问题 Solution: 没什么好说的,直接判定可行流,输出就好了 code /* 无汇源有上下界的网络流 * ...

  8. SGU 194 Reactor Cooling ——网络流

    [题目分析] 无源汇上下界可行流. 上下界网络流的问题可以参考这里.↓ http://www.cnblogs.com/kane0526/archive/2013/04/05/3001108.html ...

  9. SGU 194 Reactor Cooling (有容量和下界的可行流)

    题意:给定上一个有容量和下界的网络,让你求出一组可行解. 析:先建立一个超级源点 s 和汇点 t ,然后在输入时记录到每个结点的下界的和,建边的时候就建立c - b的最后再建立 s 和 t , 在建立 ...

随机推荐

  1. 为什么Application_BeginRequest会执行两次

       大家也看到了,很奇怪的是我们明明就请求了一个页面,页面中也没有其他的图片请求.为什么Application_BeginRequest会被执行了两次呢?!既然他请求,那我们看看他到底在请求什么就是 ...

  2. VC的话有必要认真听,但却不用急着照办

    本文来自著名风险投资人 Fred Wilson 的博客 AVC,他在 2016 年 8 月 23 日的这篇文章<Understanding VCs>里用简单的语言揭秘了 VC(风险投资人) ...

  3. op+3g

    https://forum.openwrt.org/viewtopic.php?id=44895 http://eko.one.pl/forum/viewtopic.php?id=10269 http ...

  4. Linux开发工具的使用

    1.   Linux开发工具的使用 Vim编译的使用 Gdb调试工具的使用 Makefile的编写 linux跟踪调试 SSH的使用 subversion的使用 1.   Linux开发工具的使用 V ...

  5. cf492D Vanya and Computer Game

    D. Vanya and Computer Game time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  6. Python partial函数

    以前都是摘录的其他网友的博客,很少是自己写的,学习阶段,多多学习.今天开始自己写了,首先写一下刚刚遇到的partial函数. 1.partial函数主要是对参数的改变,假如一个函数有两个参数,而其中一 ...

  7. c语言筛选质数

    #include <stdio.h> #include <stdlib.h> #include <math.h> int isit(int num) { int i ...

  8. c语言条件表达式误区1

    #include <stdio.h> #include <stdlib.h> //综合1 和 2我们知道牢记条件表达式中常量写在左边的语法规则 以防因为疏忽造成难以查找的错误 ...

  9. Android + eclipse +ADT安装完全教程

    最近几天没事做,网上看来看去突然就想弄个android来学学...  首先,是要下载android SDK,在http://developer.android.com/sdk/index.html这个 ...

  10. 验证docker的Redis镜像也存在未授权访问漏洞

    看到了这篇老外的博客:Over 30% of Official Images in Docker Hub Contain High Priority Security Vulnerabilities于 ...