bzoj 4519: [Cqoi2016]不同的最小割 最小割树
怎么求一张无向图中任意两点之间的最小割?
http://fanhq666.blog.163.com/blog/static/8194342620113495335724/
一张无向图不同的最小割最多有n-1个。
所以可以用这些最小割建出一棵最小割树。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#define inf 0x3f3f3f3f
#define N 855
#define M 400005
using namespace std;
int read()
{
int p=;char c=getchar();
while(c<''||c>'')c=getchar();
while(c>=''&&c<='')p=p*+c-'',c=getchar();
return p;
}
int head[N],ver[M],nxt[M],f[M],tot,ch[N];
void add(int a,int b,int c)
{
tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;f[tot]=c;return ;
}
queue<int>q;int S,T;
bool tell()
{
memset(ch,-,sizeof(ch));
q.push(S);ch[S]=;
while(!q.empty())
{
int tmp=q.front();q.pop();
for(int i=head[tmp];i;i=nxt[i])
{
if(f[i]&&ch[ver[i]]==-)
{
ch[ver[i]]=ch[tmp]+;
q.push(ver[i]);
}
}
}
return ch[T]!=-;
}
int zeng(int a,int b)
{
if(a==T)return b;
int r=;
for(int i=head[a];i&&b>r;i=nxt[i])
{
if(f[i]&&ch[ver[i]]==ch[a]+)
{
int t=zeng(ver[i],min(f[i],b-r));
f[i]-=t;f[i^]+=t;r+=t;
}
}
if(!r)ch[a]=-;
return r;
}
int dinic()
{
int r=,t;
while(tell())while(t=zeng(S,inf))r+=t;
return r;
}
void hui()
{
for(int i=;i<=tot;i+=)
{
f[i]=f[i^]=(f[i]+f[i^])>>;
}return ;
}
int tim;
int c[N];
void dfs(int x)
{
c[x]=tim;
for(int i=head[x];i;i=nxt[i])
{
if(f[i]&&c[ver[i]]!=tim)dfs(ver[i]);
}
return ;
}
int p[N];
int ans[N],cnt;
int n,m;
int st[N],st2[N];
void solve(int l,int r)
{
if(l==r)return ;
hui();
S=p[l];T=p[r];
int tmp=dinic();
tim++;dfs(S);
ans[++cnt]=tmp;
int top1=,top2=;
for(int i=l;i<=r;i++)
{
if(c[p[i]]==tim)st[++top1]=p[i];
else st2[++top2]=p[i];
}
for(int i=l;i<=l+top1-;i++)p[i]=st[i-l+];
for(int i=l+top1;i<=r;i++)p[i]=st2[i-l-top1+];
solve(l,l+top1-);solve(l+top1,r);
}
int main()
{
scanf("%d%d",&n,&m);
int t1,t2,t3;tot=;
for(int i=;i<=m;i++)
{
t1=read();t2=read();t3=read();
add(t1,t2,t3);add(t2,t1,t3);
}
for(int i=;i<=n;i++)p[i]=i;
solve(,n);
sort(ans+,ans+cnt+);
int as=;
for(int i=;i<=cnt;i++)
{
if(i==||ans[i]!=ans[i-])
{
as++;
}
}
printf("%d\n",as);
}
bzoj 4519: [Cqoi2016]不同的最小割 最小割树的更多相关文章
- BZOJ 4519 [CQOI2016]不同的最小割
这道题目很奇怪. 为什么奇怪?因为这道题用了一种叫分治最小割/最小割树的玩意. 以前从来没有见过这东西. 推荐一个讲这玩意的博客 写起来还是很顺手的. #include<iostream> ...
- bzoj 4519: [Cqoi2016]不同的最小割【最小割树Gomory–Hu tree】
算法详见:http://www.cnblogs.com/lokiii/p/8191573.html 求出点两两之间的最小割之后,把他们扔到map/set里跑即可 可怕的是map和set跑的时间竟然完全 ...
- BZOJ 4520 [Cqoi2016]K远点对(KD树)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=4520 [题目大意] 求K远点对距离 [题解] 修改估价函数为欧式上界估价,对每个点进行 ...
- 4519: [Cqoi2016]不同的最小割
4519: [Cqoi2016]不同的最小割 Time Limit: 20 Sec Memory Limit: 512 MB Submit: 489 Solved: 301 [Submit][Stat ...
- 【BZOJ-4519】不同的最小割 最小割树(分治+最小割)
4519: [Cqoi2016]不同的最小割 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 393 Solved: 239[Submit][Stat ...
- scu - 3254 - Rain and Fgj(最小点权割)
题意:N个点.M条边(2 <= N <= 1000 , 0 <= M <= 10^5),每一个点有个权值W(0 <= W <= 10^5),现要去除一些点(不能去掉 ...
- 算法笔记--最大流和最小割 && 最小费用最大流 && 上下界网络流
最大流: 给定指定的一个有向图,其中有两个特殊的点源S(Sources)和汇T(Sinks),每条边有指定的容量(Capacity),求满足条件的从S到T的最大流(MaxFlow). 最小割: 割是网 ...
- 3532: [Sdoi2014]Lis 最小字典序最小割
3532: [Sdoi2014]Lis Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 865 Solved: 311[Submit][Status] ...
- bzoj2229: [Zjoi2011]最小割(分治最小割+最小割树思想)
2229: [Zjoi2011]最小割 题目:传送门 题解: 一道非常好的题目啊!!! 蒟蒻的想法:暴力枚举点对跑最小割记录...绝对爆炸啊.... 开始怀疑是不是题目骗人...难道根本不用网络流?? ...
随机推荐
- 使用OpenCV通过摄像头捕获实时视频并探测人脸
在Opencv初接触,图片的基本操作这篇手记中,我介绍了一些图片的基本操作,视频可以看作是一帧一帧的图片,因此图片操作其实是视频操作的基础,这篇手记就来讲讲OpenCV中的视频操作,并实现一个用笔记本 ...
- Scrum立会报告+燃尽图(十二月七日总第三十八次):功能测试
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://git.coding.net/zhang ...
- BugPhobia开发篇章:Scurm Meeting-更新至0x03
0x01 :目录与摘要 If you weeped for the missing sunset, you would miss all the shining stars 索引 提纲 整理与更新记录 ...
- Daily Scrum (2015/11/1)
今天晚上我们照例召开了每周末的小组例会,主要总结本周的工作和讨论下一周的工作. 首先是本周的一些主要工作: 1.进行了代码的修改和完善. 2.开始进行服务器配置和UI. 3.学习借鉴了nutch爬虫的 ...
- Leetcode题库——17.电话号码的字母组合
@author: ZZQ @software: PyCharm @file: letterCombinations.py @time: 2018/10/18 18:33 要求:给定一个仅包含数字 2- ...
- 个人作业2——APP案例分析
产品:网易LOFTER(乐乎) 网易LOFTER是网易旗下图片社交APP,产品覆盖web及移动各端. 网易LOFTER社区内汇聚了多领域的品质生活家与生活达人,包含女神.明星.穿搭.文具.旅行.美 ...
- 蜗牛慢慢爬 LeetCode 9. Palindrome Number [Difficulty: Easy]
题目 Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could nega ...
- TCP连接 三次握手 四次挥手
前言: TCP协议是面向连接.安全可靠.基于字节流的传输层协议,在进行http协议访问时就用到了tcp连接.在建立TCP连接时需要经历三次握手,断开连接时需要经历四次挥手.在此进行记录. 内容: TC ...
- Beta阶段DAY3
一.提供当天站立式会议照片一张 二.每个人的工作 1.讨论项目每个成员的昨天进展 刘阳航:尝试改进UI,美化界面. 林庭亦:调整难度设置. 郑子熙:尝试改进UI,美化界面. 陈文俊:调整难度设置. 2 ...
- delphi中将一个ADOQuery查询的数据结果传递给一个动态生成的ADOQuery
delphi中将一个ADOQuery查询的数据结果传递给一个动态生成的ADOQuery 2010-03-10 17:35 方法一: beginADOQuery:=TADOQuery.Create(Ap ...