BZOJ2229—— [Zjoi2011]最小割
0、题目大意:求两点之间的最小割,然后找出其中小于x的数量
1、分析:最小割树水题,上个板子就好
#include <queue> #include <ctime> #include <cstdio> #include <cstring> #include <cstring> #include <algorithm> using namespace std; #define LL long long #define inf 214748364 inline int read(){ char ch = getchar(); int x = 0, f = 1; while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); } while('0' <= ch && ch <= '9'){ x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } struct Edge{ int from, to, cap, flow, next; }; int head[310], cur[310]; Edge G[20010]; int tot; int d[310]; bool vis[310]; int s, t, n, m; int a[310]; int ans[310][310]; int b[310]; 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 Clear(){ for(int i = 0; i <= tot; i += 2){ G[i].flow = G[i ^ 1].flow = (G[i].flow + G[i ^ 1].flow) / 2; } } 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 solve(int l, int r){ if(l == r) return; s = a[l], t = a[r]; Clear(); int tw = maxflow(); memset(vis, 0, sizeof(vis)); DFS(s); for(int i = 1; i <= n; i ++) if(vis[i]){ for(int j = 1; j <= n; j ++) if(!vis[j]){ ans[i][j] = ans[j][i] = min(ans[i][j], 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(){ int T = read(); while(T --){ n = read(); m = read(); init(); for(int i = 1; i <= m; i ++){ int u = read(), v = read(), w = read(); insert(u, v, w); insert(v, u, w); } for(int i = 1; i <= n; i ++){ for(int j = 1; j <= n; j ++){ ans[i][j] = 214748364; } } for(int i = 1; i <= n; i ++) a[i] = i; solve(1, n); int q = read(); while(q --){ LL ret = 0; int x = read(); for(int i = 1; i <= n; i ++){ for(int j = i + 1; j <= n; j ++){ ret += (ans[i][j] <= x ? 1 : 0); } } printf("%lld\n", ret); } puts(""); } return 0; }
BZOJ2229—— [Zjoi2011]最小割的更多相关文章
- BZOJ2229: [Zjoi2011]最小割
题解: 真是一道神题!!! 大家还是围观JZP的题解吧(网址找不到了...) 代码: #include<cstdio> #include<cstdlib> #include&l ...
- bzoj千题计划139:bzoj2229: [Zjoi2011]最小割
http://www.lydsy.com/JudgeOnline/problem.php?id=2229 最小割树介绍:http://blog.csdn.net/jyxjyx27/article/de ...
- bzoj2229: [Zjoi2011]最小割(分治最小割+最小割树思想)
2229: [Zjoi2011]最小割 题目:传送门 题解: 一道非常好的题目啊!!! 蒟蒻的想法:暴力枚举点对跑最小割记录...绝对爆炸啊.... 开始怀疑是不是题目骗人...难道根本不用网络流?? ...
- [bzoj2229][Zjoi2011]最小割_网络流_最小割树
最小割 bzoj-2229 Zjoi-2011 题目大意:题目链接. 注释:略. 想法: 在这里给出最小割树的定义. 最小割树啊,就是这样一棵树.一个图的最小割树满足这棵树上任意两点之间的最小值就是原 ...
- BZOJ2229[Zjoi2011]最小割——最小割树
题目描述 小白在图论课上学到了一个新的概念——最小割,下课后小白在笔记本上写下了如下这段话: “对于一个图,某个对图中结点的划分将图中所有结点分成两个部分,如果结点s,t不在同一个部分中,则称这个划分 ...
- BZOJ2229: [Zjoi2011]最小割(最小割树)
传送门 最小割树 算法 初始时把所有点放在一个集合 从中任选两个点出来跑原图中的最小割 然后按照 \(s\) 集合与 \(t\) 集合的归属把当前集合划分成两个集合,递归处理 这样一共跑了 \(n − ...
- bzoj2229: [Zjoi2011]最小割(最小割树)
传送门 这题是用最小割树做的(不明白最小割树是什么的可以去看看这一题->这里) 有了最小割树就很简单了……点数那么少……每次跑出一个最大流就暴力搞一遍就好了 //minamoto #includ ...
- 【BZOJ2229】[ZJOI2011]最小割(网络流,最小割树)
[BZOJ2229][ZJOI2011]最小割(网络流,最小割树) 题面 BZOJ 洛谷 题解 戳这里 那么实现过程就是任选两点跑最小割更新答案,然后把点集划分为和\(S\)联通以及与\(T\)联通. ...
- 【BZOJ2229】[Zjoi2011]最小割 最小割树
[BZOJ2229][Zjoi2011]最小割 Description 小白在图论课上学到了一个新的概念——最小割,下课后小白在笔记本上写下了如下这段话: “对于一个图,某个对图中结点的划分将图中所有 ...
随机推荐
- BZOJ树链剖分题目汇总
1036,2157,2243,4034,4196;2325,2908,3083,3159,3531,3626,3999;可以不树剖:1146;2819,2843,4448,4530.
- 自然语言20.1 WordNet介绍和使用 _
http://blog.csdn.net/ictextr9/article/details/4008703 Wordnet是一个词典.每个词语(word)可能有多个不同的语义,对应不同的sense.而 ...
- 有了这个,再也不用每次连新机器都要设置secure crt属性了
我连服务器用的是secure crt,每次ssh新服务器的时候都得手动设置字符编码和背景颜色,今天问了旁边的开发原来可以全局设置,以后连服务器的时候就再也不用手动设置相关属性了.步骤如下: 一开始点击 ...
- 修改 页面中默认的select样式
select样式定制: select { /*Chrome和Firefox里面的边框是不一样的,所以复写了一下*/ border: solid 1px #000; /*很关键:将默认的select选择 ...
- Ecshop商品促销时间精确到小时分钟和秒的设置方法 调用时间
第一步:找到admin/tempate/good_info.htm文件 把<input name="selbtn1" type="button" id=& ...
- swiper 技巧
全屏广告高度 ,加上属性. html, body { position: relative; height: 100%; } 停止自行播放 mySwiper.stopAutoplay(); 锁住状态, ...
- js搜索输入关键词
function getInput(val,a){ var id = 'ser-key'; if(a=='focus'){ document.getElementById(id).value=''; ...
- php实现发送邮件
smtp.php: <?php class smtp { /* Public Variables */ var $smtp_port; var $time_out; ...
- 负margin小记
static元素 margin-top/left负值,元素向指定方向移动, margin-bottom/right负值,元素不动,后续元素前移 float元素 左浮, ...
- SpringMVC -rest风格修改删除
REST风格