秘制神奇上下界网络流%%%

什么什么有(木)源汇可行流什么的,,看不懂(一下纯属个人sb言论)

看了半天知道点,一个点u,从S连到u的流量是全部流入u的下界,u到T是全部流出u的下界和。(进去出来的约一下)

感觉这个的意思就是保持从进入到出来的下界都符合(强行构造相等??),并且如果能满流,则上界也符合。那么就是可行的。

看了个有上下界最大流什么的,连一个从T-S的边,然后原图就成了无原汇了,那么再加TT,SS,搞上面的,判断可行的同时可以得出来S-T的流量,是一个可行流量。设为sum1.

那么去掉S-T的边和SS,TT点,在跑了一遍的图上跑最大流,就是使原有的图继续增广,可以得出另一个最大流sum2,那么ans=sum1+sum2。(就看了这么一点,sb)

 #include<bits/stdc++.h>
#define N 100005
#define LL long long
#define inf 0x3f3f3f3f
#define ls tr[x][0]
#define rs tr[x][1]
using namespace std;
inline int ra()
{
int x=,f=; char ch=getchar();
while (ch<'' || ch>'') {if (ch=='-') f=-; ch=getchar();}
while (ch>='' && ch<='') {x=x*+ch-''; ch=getchar();}
return x*f;
}
const int S=,T=;
int n,m,cnt;
int head[],cur[],h[],q[],in[];
int low[];
struct data{int to,next,v;}e[];
void ine(int x, int y, int v)
{
e[++cnt].to=y;
e[cnt].next=head[x];
e[cnt].v=v;
head[x]=cnt;
}
void insert(int x, int y, int v)
{
ine(x,y,v); ine(y,x,);
}
bool bfs()
{
for (int i=; i<=T; i++) h[i]=-;
int l=,r=; q[]=S; h[S]=;
while (l<r)
{
int x=q[l++];
for (int i=head[x];i;i=e[i].next)
if (e[i].v && h[e[i].to]==-)
{
h[e[i].to]=h[x]+;
q[r++]=e[i].to;
}
}
if (h[T]==-) return ;
return ;
}
int dfs(int x, int f)
{
if (x==T) return f;
int w,ww=;
for (int i=head[x];i;i=e[i].next)
if (h[e[i].to]==h[x]+)
{
w=dfs(e[i].to,min(e[i].v,f-ww));
ww+=w; e[i].v-=w; e[i^].v+=w;
if (ww==f) return f;
}
if (!ww) h[x]=-;
return ww;
}
void dinic()
{
while (bfs()) dfs(S,inf);
}
void build()
{
for (int i=; i<=n; i++)
if (in[i]>) insert(S,i,in[i]);
else insert(i,T,-in[i]);
}
bool jud()
{
for (int i=head[S];i;i=e[i].next)
if (e[i].v) return ;
return ;
}
int main()
{
int t=ra();
while (t--)
{
cnt=;
memset(head,,sizeof(head));
memset(in,,sizeof(in));
n=ra(); m=ra();
for (int i=; i<=m; i++)
{
int x=ra(),y=ra(); low[i]=ra(); int w=ra();
in[x]-=low[i]; in[y]+=low[i];
insert(x,y,w-low[i]);
}
build(); dinic();
if (!jud()) cout<<"NO"<<endl;
else{
cout<<"YES"<<endl;
for (int i=; i<=m; i++)
printf("%d\n",e[(i<<)^].v+low[i]);
}
cout<<endl;
}
return ;
}

zoj 2314Reactor Cooling的更多相关文章

  1. zoj Reactor Cooling

    Reactor Cooling 无源汇上下界最大流问题. 1.流量平衡. 2.满足上下界 模板题. #include <iostream> #include <queue> # ...

  2. ZOJ 1314 Reactor Cooling | 上下界无源汇可行流

    ZOJ 1314 Reactor Cooling | 上下界无源汇可行流 题意 有一个网络,每条边有流量的上界和下界,求一种方案,让里面的流可以循环往复地流动起来. 题解 上下界无源汇可行流的模型: ...

  3. zoj 2314 Reactor Cooling 网络流

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 The terrorist group leaded by a ...

  4. ZOJ 2314 - Reactor Cooling - [无源汇上下界可行流]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 The terrorist group leaded by ...

  5. zoj 2314 Reactor Cooling (无源汇上下界可行流)

    Reactor Coolinghttp://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 Time Limit: 5 Seconds ...

  6. ZOJ 2314 Reactor Cooling

    Reactor Cooling Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...

  7. ZOJ 2314 Reactor Cooling [无源汇上下界网络流]

    贴个板子 #include <iostream> #include <cstdio> #include <cstring> #include <algorit ...

  8. ZOJ 2314 Reactor Cooling(无源汇有上下界可行流)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 题目大意: 给n个点,及m根pipe,每根pipe用来流躺 ...

  9. ZOJ 2314 Reactor Cooling(无源汇上下界网络流)

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 题意: 给出每条边流量的上下界,问是否存在可行流,如果存在则输出. ...

随机推荐

  1. @Controller 和 @RestController 的区别

    @Controller和@RestController的区别? 官方文档:@RestController is a stereotype annotation that combines @Respo ...

  2. luogu P3357 最长k可重线段集问题

    这题和3358一模一样,建模形式直接不用变,就两点不一样,一是len变化了,加入y后再更新即可,还有就是可能会出现x0=x1的情况,即一条开线段垂直x轴,如果我们依旧按照上一题的建图方法,就会出现负权 ...

  3. Link Analysis_2_Application

    US Cities Distribution Network 1.1 Task Description Nodes: Cities with attributes (1) location, (2) ...

  4. Linux之文件传输

    本文借鉴<Linux命令大全> 1. bye命令 功能:终端FTP连线并结束程序 语法:bye 补充:在ftp模式下,输入bye即可中断目前的连线作业,并结束ftp的执行. 2. ftp命 ...

  5. php: 文件上传

    1.主页: <!DOCTYPE html><html lang="en"><head>    <meta charset="UT ...

  6. 为什么mysql having的条件表达式可以直接使用select后的别名?

    SQL语句的语法顺序: FROM -> WHERE -> GROUP BY -> HAVING -> SELECT -> DISTINCT -> UNION -&g ...

  7. python列表元组 魔法方法

    1.元祖 count()    统计某个字符串的出现次数 tuple.count('22')    返回一个整数 index()    获取某个值出现的位置 2.列表 字符串可以直接转换列表    l ...

  8. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 辅助类:"text-muted" 类的文本样式

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  9. PLCsim 软件模拟OB86故障

    用上一节 组态DP主站与标准从站的方法 组态了网络 实现了 将profibus –dp 标准从站 ET200M 下 输入地址为IW2 接口的状态 读取到 主机 DP-315-2DP 的QW0 变量以来 ...

  10. 51nod 1368:黑白棋 二分图最大匹配

    1368 黑白棋 题目来源: TopCoder 基准时间限制:1 秒 空间限制:131072 KB 分值: 160 难度:6级算法题  收藏  取消关注 有一个N*M的棋盘(1<=N,M< ...