LibreOJ #115. 无源汇有上下界可行流
二次联通门 : LibreOJ #115. 无源汇有上下界可行流
/*
LibreOJ #115. 无源汇有上下界可行流
板子题
我也就会写写板子题了。。
*/
#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>
const int BUF = ;
char Buf[BUF], *buf = Buf;
void read (int &now)
{
for (now = ; !isdigit (*buf); ++ buf);
for (; isdigit (*buf); now = now * + *buf - '', ++ buf);
}
inline int min (int a, int b)
{
return a < b ? a : b;
}
#define Max 800
#define INF 1e8
int _S, _T;
int low[Max << ], _in[Max];
class Net_Flow
{
private :
int to[Max << ], _next[Max << ], flow[Max << ];
int C, list[Max << ], deep[Max << ], _tech[Max << ];
int S, T;
public :
inline void In (int u, int v, int w)
{
to[++ C] = v, _next[C] = list[u], list[u] = C;
to[++ C] = u, _next[C] = list[v], list[v] = C;
flow[C] = , flow[C - ] = w;
}
void Clear ()
{
C = , S = _S, T = _T;
}
int Flowing (int now, int Flow)
{
if (now == T || Flow == )
return Flow;
register int res = , pos;
for (int &i = _tech[now]; i; i = _next[i])
{
if (deep[to[i]] != deep[now] + || flow[i] == )
continue;
pos = Flowing (to[i], min (flow[i], Flow));
if (pos > )
{
flow[i] -= pos, res += pos, flow[i ^ ] += pos;
Flow -= pos; if (Flow <= ) break;
}
}
if (res != Flow) deep[now] = -;
return res;
}
bool Bfs ()
{
std :: queue <int> Queue;
memset (deep, -, sizeof deep);
Queue.push (S), deep[S] = ; register int i, now;
for (; !Queue.empty (); Queue.pop ())
{
now = Queue.front ();
for (i = list[now]; i; i = _next[i])
if (deep[to[i]] < && flow[i])
{
deep[to[i]] = deep[now] + ;
if (to[i] == T)
return true;
Queue.push (to[i]);
}
}
return deep[T] != -;
}
int Dinic ()
{
int res = ;
for (; Bfs (); )
{
for (int i = S; i <= T; ++ i)
_tech[i] = list[i];
res += Flowing (S, INF);
}
return res;
}
void Print (const int &M)
{
printf ("YES\n");
for (int i = ; i <= M; ++ i)
printf ("%d\n", low[i] + flow[i << | ]);
}
};
Net_Flow Flow;
//#define Local
int Main ()
{
#ifdef Local
freopen ("yukari.wife", "r", stdin);
#endif
fread (buf, , BUF, stdin);
int N, M;
read (N);
read (M);
int u, v, up;
_S = , _T = N + , Flow.Clear ();
for (int i = ; i <= M; ++ i)
{
read (u), read (v), read (low[i]), read (up);
Flow.In (u, v, up - low[i]);
_in[u] -= low[i], _in[v] += low[i];
}
int Total = ;
for (int i = ; i <= N; ++ i)
if (_in[i] > )
Total += _in[i], Flow.In (_S, i, _in[i]);
else if (_in[i] < )
Flow.In (i, _T, -_in[i]);
if (Flow.Dinic () != Total)
return printf ("NO"), ;
else Flow.Print (M);
return ;
}
int ZlycerQan = Main ();
int main (int argc, char *argv[]) {; }
LibreOJ #115. 无源汇有上下界可行流的更多相关文章
- LOJ [#115. 无源汇有上下界可行流](https://loj.ac/problem/115)
#115. 无源汇有上下界可行流 先扔个板子,上下界的东西一点点搞,写在奇怪的合集里面 Code: #include <cstdio> #include <cstring> # ...
- [loj#115] 无源汇有上下界可行流 网络流
#115. 无源汇有上下界可行流 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:Special Judge 上传者: 匿名 提交提交记录统计讨论测试数据 题 ...
- 2018.08.20 loj#115. 无源汇有上下界可行流(模板)
传送门 又get到一个新技能,好兴奋的说啊. 一道无源汇有上下界可行流的模板题. 其实这东西也不难,就是将下界变形而已. 准确来说,就是对于每个点,我们算出会从它那里强制流入与流出的流量,然后与超级源 ...
- loj#115. 无源汇有上下界可行流
\(\color{#0066ff}{ 题目描述 }\) 这是一道模板题. \(n\) 个点,\(m\) 条边,每条边 \(e\) 有一个流量下界 \(\text{lower}(e)\) 和流量上界 \ ...
- 【LOJ115】无源汇有上下界可行流(模板题)
点此看题面 大致题意: 给你每条边的流量上下界,让你判断是否存在可行流.若有,则还需输出一个合法方案. 大致思路 首先,每条边既然有一个流量下界\(lower\),我们就强制它初始流量为\(lower ...
- Zoj 2314 Reactor Cooling(无源汇有上下界可行流)
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1314 题意: 给n个点,及m根pipe,每根pipe用来流躺液体的,单向 ...
- 无源汇有上下界可行流(ZQU 1590)
无源汇有上下界可行流(也就是循环流) 模型:一个网络,求出一个流,使得每条边的流量必须>=Li且<=Hi, 每个点必须满足总流入量=总流出量(流量守恒)(这个流的特点是循环往复,无始无终) ...
- 【模板】无源汇有上下界可行流(网络流)/ZOJ2314
先导知识 网络最大流 题目链接 https://vjudge.net/problem/ZOJ-2314 题目大意 多组数据,第一行为数据组数 \(T\). 对于每一组数据,第一行为 \(n,m\) 表 ...
- ZOJ 2314 Reactor Cooling(无源汇有上下界可行流)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2314 题目大意: 给n个点,及m根pipe,每根pipe用来流躺 ...
随机推荐
- Android--文件存取
import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundExc ...
- WPF打印控件内容
当我们想打印控件内容时,如一个Grid中的内容,可以用WPF中PrintDialog类的PrintVisual()方法来实现 界面如下: XAML代码如下 <Grid> <Grid. ...
- C#基础加强笔记
1面向对象 类:包含字段.属性.函数.构造函数 字段:存储数据 属性:保护字段 get set 函数:描述对象的行为 构造函数:初始化对象,给对象的每个属性赋值 面向对象的好处:让程序具有扩展性 类决 ...
- VBA分别使用MSXML的DOM属性和XPATH进行网页爬虫
本文要重点介绍的是VBA中的XmlHttp对象(MSXML2.XMLHTTP或MSXML.XMLHTTP),它可以向http服务器发送请求并使用微软XML文档对象模型Microsoft XML Doc ...
- Java Web-JQuery学习
Java Web-JQuery学习 JQuery概念 是一个JS框架,可以用来简化JS的开发,设计宗旨是"write less,do more",即写更少的代码,做更多的事情.它封 ...
- CSS_引入方式
一 CSS的引入方式 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,用来控制网页数据的表现,可以使网页的表现与数据内容分离 1.行内式 ...
- iOS开发微信支付的介绍与实现
1.前期准备 1) 到微信开放平台注册账号 需要登录邮箱验证 填写您的商户信息 2) 进入管理中心 --- 移动应用 --- 创建移动应用 --- 根据页面完善应用资料 3) 审核过后,通过应用详情页 ...
- lumen路由配置nginx
nginx配置文件中添加: set $root_path '/data/www/m.domain.com/public'; root $root_path; location / { ...
- 基本代码、插值表达式、v-cloak
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- uboot中setenv和saveenv分析
转:https://blog.csdn.net/weixin_34355715/article/details/85751477 Env在u-boot中通常有两种存在方式,在永久性存储介质中(flas ...