bzoj4435: [Cerc2015]Juice Junctions(最小割树+hash)

news/2024/7/3 4:26:05

传送门

 

首先最大流等于最小割,那么可以转化为最小割树来做(不知道什么是最小割树的可以看看这题->这里)

具体的做法似乎是$hash[i][j]$表示最小割为$i$时点$j$是否与$S$连通

然后据Claris大爷说这题卡dinic,只能用EK

顺便吐槽一句,Claris大爷的代码真的不能看……

 1 //minamoto
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<algorithm>
 7 #define inf 0x3f3f3f3f3
 8 using namespace std;
 9 #define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
10 char buf[1<<21],*p1=buf,*p2=buf;
11 inline int read(){
12     #define num ch-'0'
13     char ch;bool flag=0;int res;
14     while(!isdigit(ch=getc()))
15     (ch=='-')&&(flag=true);
16     for(res=num;isdigit(ch=getc());res=res*10+num);
17     (flag)&&(res=-res);
18     #undef num
19     return res;
20 }
21 const int N=3005;
22 int ver[N<<2],Next[N<<2],edge[N<<2],head[N],tot=1;
23 inline void add(int u,int v,int e){
24     ver[++tot]=v,Next[tot]=head[u],head[u]=tot,edge[tot]=e;
25     ver[++tot]=u,Next[tot]=head[v],head[v]=tot,edge[tot]=e;
26 }
27 int dep[N],q[N],n,m,S,T,ans;
28 bool bfs(){
29     int l=0,r=1;memset(dep+1,-1,sizeof(int)*n);dep[q[0]=S]=0;
30     while(l<r){
31         int u=q[l++];
32         for(int i=head[u];i;i=Next[i])
33         if(dep[ver[i]]<0&&edge[i])
34         dep[ver[i]]=i,q[r++]=ver[i];
35     }
36     return ~dep[T];
37 }
38 int id[N],tmp[N];
39 unsigned Pow=1,Hash[4][N];
40 void solve(int L,int R){
41     if(L==R) return;
42     for(int i=2;i<=tot;i+=2)
43     edge[i]=edge[i^1]=1;
44     S=id[L],T=id[R];int flow=0,j;
45     while(bfs()){
46         ++flow;
47         for(int i=T;i!=S;i=ver[j^1]) --edge[j=dep[i]],++edge[j^1];
48     }
49     Pow*=233;
50     for(int i=1;i<=n;++i)
51     if(~dep[i]) Hash[flow][i]+=Pow;
52     int l=L,r=R;
53     for(int i=L;i<=R;++i)
54     if(~dep[id[i]]) tmp[l++]=id[i];
55     else tmp[r--]=id[i];
56     memcpy(id+L,tmp+L,sizeof(int)*(R-L+1));
57     solve(L,l-1),solve(r+1,R);
58 }
59 int main(){
60     //freopen("testdata.in","r",stdin);
61     n=read(),m=read();
62     for(int i=1,u,v;i<=m;++i)
63     u=read(),v=read(),add(u,v,1);
64     for(int i=1;i<=n;++i) id[i]=i;
65     solve(1,n);
66     for(int i=1;i<=n;++i)
67     for(int j=i+1;j<=n;++j)
68     for(int k=0;k<=3;++k)
69     if(Hash[k][i]!=Hash[k][j]) {ans+=k;break;}
70     printf("%d\n",ans);
71     return 0;
72 }

 

转载于:https://www.cnblogs.com/bztMinamoto/p/9571156.html


http://www.niftyadmin.cn/n/2257145.html

相关文章

Hadoop2.x分布式集群环境搭建

引言 大数据已经是当今这个时代非常非常热的一个技术方向&#xff0c;所有的行业都在利用大数据提升业务&#xff0c;包括很多的实体行业&#xff0c;制造企业&#xff0c;都希望利用现有的数据、亦或是可以爬取的数据。挖掘出更多的商业价值。曾经我的驾校教练就和我说过一个场…

『一起欣赏』50+ 极具创意的简历设计【上篇】

这篇文章收集了50非常有创意的简历设计作品与大家分享&#xff0c;相比国内求职者中规中矩的简历&#xff0c;这些国外的简历设计非常新颖&#xff0c;让人眼前一亮&#xff01;一份让人眼前一亮的简历也许就能带给你一份不错的工作&#xff0c;一起欣赏&#xff01; 您可能感兴…

介绍一款jquery的autocomplete插件

官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ Jquery AutoComplete的使用方法实例 jQuery的Autocomplete&#xff08;自动完成、自动填充&#xff09;插件有不少&#xff0c;但比较下来我感觉&#xff0c;还是bassistance.de的JQuery Autocompl…

9.1总结前日(数学+图论)

后天就要开学了&#xff0c;这应该是这个暑假的最后一次总结了吧。 说实话&#xff0c;忙忙碌碌的一个暑假&#xff0c;学到东西了么&#xff1f;学到了。学了多少&#xff1f;还可以吧hhh。 想起来去年的这个时候&#xff0c;我还抱着紫书在那里看爆搜&#xff0c;啥也看不懂&…

IDEA搭建项目

【搭建 spring&#xff08;SSM&#xff09; 项目】 【使用IDEA搭建Maven SSM框架】 https://www.cnblogs.com/jingpeipei/p/6291071.html 【GitHub 简单的SSM项目】 https://github.com/qidasheng2012/ssm_simple 【GitHub 多模块的SSM项目】 https://github.com/qidashen…

strongswan--ikev2软件架构

strongswan IKEv2后台进程的软件架构图 processor是任务管理器&#xff0c;负责对线程&#xff08;threads&#xff09;和作业&#xff08;jobs&#xff09;进行管理&#xff0c;其结构为private_processor_t。 worker_thread_t为工作线程的结构&#xff0c;包括实际的线程&…

求N!的二进制表示中最低位1的位置?

解法一&#xff1a;如果n!最末尾位0&#xff0c;则右移一位得到商&#xff0c;如果末尾是1&#xff0c;则不能被2整除&#xff0c;是奇数&#xff0c;这个问题等同与求n!中质有质因数2的个数。。最后结果再加1 代码&#xff1a; #include<iostream> using namespace std;…

Viewer.js – 强大的JS/jQuery图片查看器

前序 在后管开发过程中经常需要对图片显示、放大、轮播、翻转等 使用篇 http://www.dowebok.com/192.html