CodeForces1082G Petya and Graph 最小割
网络流裸题
\(s\)向点连边\((s, i, a[i])\)
给每个边建一个点
边\((u, v, w)\)抽象成\((u, E, inf)\)和\((v, E, inf)\)以及边\((E, t, w)\)
最小割建模...
然后就没了....复习一下板子吧
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;#define ll long long
#define ri register int
#define rep(io, st, ed) for(ri io = st; io <= ed; io ++)
#define drep(io, ed, st) for(ri io = ed; io >= st; io --)#define gc getchar
inline int read() {int p = 0, w = 1; char c = gc();while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); }while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();return p * w;
}const int sid = 5e4 + 5;
const ll inf = 1e17;int n, m, s, t, ip, cnp = 1;
int a[sid], q[sid], go[sid], num[sid], L[sid];
int cap[sid], nxt[sid], node[sid];
ll res[sid];inline void addedge(int u, int v, ll w) {nxt[++ cnp] = cap[u]; cap[u] = cnp; node[cnp] = v; res[cnp] = w;nxt[++ cnp] = cap[v]; cap[v] = cnp; node[cnp] = u; res[cnp] = 0;
}#define cur node[i]
inline void bfs() {int fr = 1, to = 0;L[t] = 1; num[1] ++; q[++ to] = t;while(fr <= to) {int o = q[fr ++];for(int i = cap[o]; i; i = nxt[i])if(res[i ^ 1] && !L[cur]) {q[++ to] = cur;L[cur] = L[o] + 1; num[L[cur]] ++;}}for(int i = 1; i <= t; i ++) go[i] = cap[i];
}inline ll dfs(int o, ll flow) {ll tt = 0, tmp;if(o == t) return flow;for(int &i = go[o]; i; i = nxt[i]) {if(L[cur] + 1 != L[o]) continue;tmp = dfs(cur, min(flow, res[i]));res[i] -= tmp; res[i ^ 1] += tmp;flow -= tmp; tt += tmp;if(!flow) return tt;}-- num[L[o]]; if(!num[L[o]]) L[s] = t + 1;L[o] ++; num[L[o]] ++;go[o] = cap[o];return tt;
}inline ll isap(int s, int t) {bfs();ll ret = dfs(s, inf);while(L[s] <= t) ret += dfs(s, inf);return ret;
}int main() {ll ans = 0;n = read(); m = read();rep(i, 1, n) a[i] = read();s = n + m + 1; t = s + 1;rep(i, 1, n) addedge(s, i, a[i]);rep(i, 1, m) {int u = read(), v = read(), w = read();addedge(u, n + i, inf); addedge(v, n + i, inf);addedge(n + i, t, w); ans += w;}ans -= isap(s, t);printf("%lld\n", ans);return 0;
}
转载于:https://www.cnblogs.com/reverymoon/p/10164746.html
CodeForces1082G Petya and Graph 最小割相关推荐
- CF1082G Petya and Graph(最小割,最大权闭合子图)
QWQ嘤嘤嘤 感觉是最水的一道\(G\)题了 顺便记录一下第一次在考场上做出来G qwqqq 题目大意就是说: 给你n个点,m条边,让你选出来一些边,最大化边权减点权 \(n\le 1000\) QW ...
- Destroying The Graph 最小点权集--最小割--最大流
Destroying The Graph 构图思路: 1.将所有顶点v拆成两个点, v1,v2 2.源点S与v1连边,容量为 W- 3.v2与汇点连边,容量为 W+ 4.对图中原边( a, b ), ...
- 【BZOJ-2400】Spoj839Optimal Marks 最小割 + DFS
2400: Spoj 839 Optimal Marks Time Limit: 10 Sec Memory Limit: 128 MB Submit: 567 Solved: 202 [Subm ...
- CF1146G Zoning Restrictions 最小割
CF1146G Zoning Restrictions 最小割 题意: 你准备在一条街上建房子.这条街上共有nn个地方可以用来建房子,每个房子高度最高为h.若你建了一个高度为aa的房子,那你将得到a^ ...
- 网络流:最大流,最小割 基本概念及算法
原文:http://www.cnblogs.com/Booble/archive/2011/03/04/1970453.html 参考:http://community.topcoder.com/tc ...
- 最大流与最小割(Maxflow与Mincut)
传统图像主要分割算法: 基于阈值的分割 (1)固定阈值分割 (2)直方图双峰法 (3)迭代阈值图像分割 (4)自适应阈值图像分割 (5)最佳阈值法 2.基于边缘的分割 (1)Canny边缘检测器 (2 ...
- 基于最小割的分割算法(Min-Cut Based Segmentation)
参考: https://www.cnblogs.com/ironstark/p/5008258.html https://github.com/Ewenwan/MVision/blob/master/ ...
- HDU 3313 Key Vertex 胡搞(网络流最小割拆点什么的人家才不会呢)
problem大意:给you一个无loop有向graph,求它的key vertex数目.(最近刚过了英语六级,耶,1Y,炫耀~~~~~) 什么是key vertex呢?就是去掉以后从起点到不了终点了 ...
- HDU 5457 Hold Your Hand【最小割+字典树】
在这里先感谢YYN菊苣对我解题的帮助. 首先,我们按照前缀和后缀建立两棵字典树. 节点总数为256∗8∗2256*8*2,每一个叶子节点是我们的数字. 其次,我们对读入的操作来更新字典树,假设字典树有 ...
最新文章
- 为什么选择格鲁圣教之Go程序版
- vue搜不到c_vue不是内部命令、安装@vue/cli失败、找不到vue.cmd文件等问题的解决方法...
- Atcoder AGC031C Differ By 1 Bit (构造、二进制)
- Eclipse中Build Path的使用介绍---学习笔记
- 2018,程序员要搭配这40条编程箴言!!!条条都是干货
- kotlin的属性代理
- 2020年IPTV系统解决方案应该注意哪些问题?
- dumpDex脱壳教程
- STC8G1K08A之PWM占空比调整
- FaceX-Zoo: A PyTocrh Toolbox for Face Recognition
- python使用opencv通过掩码提取彩色图片感兴趣区域
- java小游戏实训目的_Java弹球小游戏实验报告.doc
- Zabbix - 微信报警
- Linux服务器的eth,Linux服务器---网络配置
- C语言编程实现,计算每天进步一点点一年后的效果
- 我又双叒叕赶来科普了
- 物流仓储管理中超高频RFID的应用
- SpringBoot实现SpringTask调度任务---实现间隔调度与CRON调度处理
- 【尚硅谷云原生Java架构师的第一课 4 2021-09-28】KubeSphere三种安装,docker,k8s,nfs安装,metrics。KubeKey一键单 多节点安装。
- 东南亚电商市场不欢迎独立站