BZOJ4519——[cqoi2016]不同的最小割
0、题意:求两点之间的最小割的不同的总量
1、分析:裸的分治+最小割,也叫最小割树或GH树,最后用set搞一下就好
#include <set>
#include <queue>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
#define inf 214748364
struct Edge{
int from, to, cap, flow, next;
};
int head[1010], cur[1010];
Edge G[40010];
int tot;
int d[1010];
bool vis[1010];
int s, t, n, m;
int a[1010];
int b[1010];
inline void init(){
memset(head, -1, sizeof(head));
tot = -1;
return;
}
inline void insert(int from, int to, int cap){
G[++ tot] = (Edge){from, to, cap, 0, head[from]};
head[from] = tot;
G[++ tot] = (Edge){to, from, 0, 0, head[to]};
head[to] = tot;
return;
}
inline bool BFS(){
memset(vis, 0, sizeof(vis));
queue<int> Q;
Q.push(s);
vis[s]=1;
d[s]=0;
while(!Q.empty()){
int x = Q.front(); Q.pop();
for(int i = head[x]; i != -1; i = G[i].next){
Edge& e = G[i];
if(e.cap - e.flow > 0 && !vis[e.to]){
vis[e.to] = 1;
d[e.to]=d[x]+1;
Q.push(e.to);
}
}
}
return vis[t];
}
inline int dfs(int x, int a){
if(x == t || a == 0) return a;
int flow = 0, f;
for(int& i = cur[x]; i != -1; i = G[i].next){
Edge& e = G[i];
if(d[x]+1 == d[e.to] && (f = dfs(e.to, min(e.cap - e.flow, a))) > 0){
e.flow += f;
G[i ^ 1].flow -= f;
flow += f;
a -= f;
if(a == 0) break;
}
}
return flow;
}
inline int maxflow(){
int res = 0;
while(BFS()){
for(int i = 1; i <= n; i ++) cur[i] = head[i];
res += dfs(s, inf);
}
return res;
}
inline void DFS(int x){
vis[x] = 1;
for(int i = head[x]; i != -1; i = G[i].next) if(!vis[G[i].to] && G[i].cap > G[i].flow){
DFS(G[i].to);
}
}
inline void Clear(){
for(int i = 0; i <= tot; i += 2){
G[i].flow = G[i ^ 1].flow = (G[i].flow + G[i ^ 1].flow) / 2;
}
}
set<int> Set;
inline void solve(int l, int r){
if(l == r) return;
s = a[l], t = a[r];
Clear();
int tw = maxflow();
Set.insert(tw);
int L = l, R = r;
for(int i = l; i <= r; i ++){
if(vis[a[i]]) b[L ++] = a[i];
else b[R --] = a[i];
}
for(int i = l; i <= r; i ++) a[i] = b[i];
solve(l, L - 1); solve(L, r);
}
int main(){
scanf("%d%d", &n, &m);
init();
for(int i = 1; i <= m; i ++){
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
insert(u, v, w); insert(v, u, w);
}
for(int i = 1; i <= n; i ++) a[i] = i;
solve(1, n);
printf("%d\n", Set.size());
return 0;
}
BZOJ4519——[cqoi2016]不同的最小割的更多相关文章
- bzoj千题计划140:bzoj4519: [Cqoi2016]不同的最小割
http://www.lydsy.com/JudgeOnline/problem.php?id=4519 最小割树 #include<queue> #include<cstdio&g ...
- bzoj4519: [Cqoi2016]不同的最小割(分治最小割)
4519: [Cqoi2016]不同的最小割 题目:传送门 题解: 同BZOJ 2229 基本一样的题目啊,就最后用set记录一下就ok 代码: #include<cstdio> #inc ...
- [bzoj4519][Cqoi2016]不同的最小割_网络流_最小割_最小割树
不同的最小割 bzoj-4519 Cqoi-2016 题目大意:题目链接. 注释:略. 想法: 我们发现这和最小割那题比较像. 我们依然通过那个题说的办法一样,构建最小割树即可. 接下来就是随便怎么处 ...
- BZOJ4519 CQOI2016不同的最小割(最小割+分治)
最小割树:新建一个图,包含原图的所有点,初始没有边.任取两点跑最小割,给两点连上权值为最小割的边,之后对于两个割集分别做同样的操作.最后会形成一棵树,树上两点间路径的最小值即为两点最小割.证明一点都不 ...
- BZOJ4519: [Cqoi2016]不同的最小割
Description 学过图论的同学都知道最小割的概念:对于一个图,某个对图中结点的划分将图中所有结点分成 两个部分,如果结点s,t不在同一个部分中,则称这个划分是关于s,t的割.对于带权图来说,将 ...
- BZOJ4519[Cqoi2016]不同的最小割——最小割树+map
题目描述 学过图论的同学都知道最小割的概念:对于一个图,某个对图中结点的划分将图中所有结点分成 两个部分,如果结点s,t不在同一个部分中,则称这个划分是关于s,t的割.对于带权图来说,将 所有顶点处在 ...
- bzoj4519: [Cqoi2016]不同的最小割(最小割树)
传送门 好神仙……最小割树是个什么东西…… 其实我觉得干脆直接$O(n^2)$跑几个dinic算了…… 来说一下这个叫最小割树的神奇东西 我们先建一个$n$个点,没有边的无向图 在原图中任选两点$s, ...
- 【BZOJ4519】[Cqoi2016]不同的最小割 最小割树
[BZOJ4519][Cqoi2016]不同的最小割 Description 学过图论的同学都知道最小割的概念:对于一个图,某个对图中结点的划分将图中所有结点分成两个部分,如果结点s,t不在同一个部分 ...
- 【BZOJ-4519】不同的最小割 最小割树(分治+最小割)
4519: [Cqoi2016]不同的最小割 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 393 Solved: 239[Submit][Stat ...
随机推荐
- Visual Studio 当前上下文中不存在名称“ConfigurationManager”
Visual Studio调试出现错误:当前上下文中不存在名称“ConfigurationManager” 解决方法: 1.System.Configuration引用这个dll参考:http://k ...
- mongo&node
///// node install $ sudo apt-get install python-software-properties $ curl -sL https://deb.nodesou ...
- Jsonp类
public class JsonpResult : JsonResult { public JsonpResult() { this.Callback = "callback"; ...
- aircrack-ng 多网卡启动后环境清理
#!/bin/sh pkill airodump airmon-ng stop wlan0mon service network-manager restart rm -rf sadsad*
- 10月17日下午MySQl数据库CRUD高级查询
高级查询:1.连接查询 #适用于有外键关系的 没有任何关系没法用select * from Info,Nation #同时查询这俩表并把两表每个数据相互组合,形成笛卡尔积 select * from ...
- Set接口
Set接口也是Collection接口的子接口,Set接口中不能加入重复的元素 Set接口的常用子类 1.散列的存放:HashSet HashSet是Set接口的一个子类,主要的特点是:里面不能存放重 ...
- thinkphp新增
$m = M('content'); //与 $m = new Model('content')效果一样 $date = array( 'username' => I('username', ...
- IOS: 账号,证书 好文整理
公钥.私钥.数字证书的概念 http://blog.csdn.net/turui/article/details/2048582 iOS Provisioning Profile(Certificat ...
- thinkphp 模板里a标签 href 带参数的 使用U函数方法
简单的说就是模板里 分类的链接地址 实现这个样子的 <a href="/index.php/Home/Category/assortment/cateid/2.html"&g ...
- 负margin小记
static元素 margin-top/left负值,元素向指定方向移动, margin-bottom/right负值,元素不动,后续元素前移 float元素 左浮, ...