[CERC2015]Juice Junctions(边双连通+字符串hash)
做法
考虑边数限制的特殊条件,显然答案仅有\(\{0,1,2,3\}\)
0:不联通
1:连通
2:边双连通
3:任意删掉一条边都为边双连通
考虑每次删边后记录各点的边双染色情况来特判\(3\):是否所有情况都相同
Code
#include<bits/stdc++.h>
typedef int LL;
typedef long long ll;
const LL maxn=1e6+9,inf=0x3f3f3f3f;
const ll base_1=233,base_2=2333,mod1=99991,mod2=99989;
inline LL Read(){
LL x(0),f(1); char c=getchar();
while(c<'0' || c>'9'){
if(c=='-') f=-1; c=getchar();
}
while(c>='0' && c<='9'){
x=(x<<3)+(x<<1)+c-'0'; c=getchar();
}return x*f;
}
struct node{
LL to,nxt;
}dis[maxn];
LL n,m,top,num,nod,tim,ban,ans;
LL head[maxn],col[maxn],sta[maxn],dfn[maxn],low[maxn],f[maxn],hash_1[maxn],hash_2[maxn];
ll hash1[maxn],hash2[maxn];
inline void Add(LL u,LL v){
dis[++num]=(node){v,head[u]}; head[u]=num;
}
void Tarjan(LL u,LL fa){
dfn[u]=low[u]=++tim; sta[++top]=u;
for(LL i=head[u];i;i=dis[i].nxt){
LL v(dis[i].to);
if(v==fa || i==ban || i==ban-1) continue;
if(!dfn[v]){
Tarjan(v,u); low[u]=std::min(low[u],low[v]);
}else low[u]=std::min(low[u],dfn[v]);
}
if(low[u]==dfn[u]){
LL now; ++nod;
do{
now=sta[top--]; col[now]=nod;
}while(now!=u);
}
}
LL Find(LL x){
return f[x]==x?x:f[x]=Find(f[x]);
}
inline void Union(LL u,LL v){
f[Find(u)]=Find(v);
}
int main(){
n=Read(); m=Read();
for(LL i=1;i<=n;++i) f[i]=i;
for(LL i=1;i<=m;++i){
LL u(Read()),v(Read());
Add(u,v); Add(v,u);
Union(u,v);
}
for(LL i=1;i<=n;++i)
if(!dfn[i])
Tarjan(i,0);
for(LL i=1;i<=n;++i)
for(LL j=i+1;j<=n;++j)
ans+=(Find(i)==Find(j)) + (col[i]==col[j]);
for(ban=2;ban<=(m<<1);ban+=2){
memset(dfn,0,4*(n+1)); nod=top=tim=0;
for(LL i=1;i<=n;++i)
if(!dfn[i])
Tarjan(i,0);
for(LL i=1;i<=n;++i){
hash_1[i]=(hash_1[i]*base_1%mod1+col[i])%mod1;
hash_2[i]=(hash_2[i]*base_2%mod1+col[i])%mod2;
}
}
for(LL i=1;i<=n;++i)
for(LL j=i+1;j<=n;++j)
ans+=(hash_1[i]==hash_1[j] && hash_2[i]==hash_2[j]);
printf("%d\n",ans);
return 0;
}
[CERC2015]Juice Junctions(边双连通+字符串hash)的更多相关文章
- bzoj4435: [Cerc2015]Juice Junctions(最小割树+hash)
传送门 首先最大流等于最小割,那么可以转化为最小割树来做(不知道什么是最小割树的可以看看这题->这里) 具体的做法似乎是$hash[i][j]$表示最小割为$i$时点$j$是否与$S$连通 然后 ...
- 【BZOJ4435】[Cerc2015]Juice Junctions Tarjan+hash
[BZOJ4435][Cerc2015]Juice Junctions Description 你被雇佣升级一个旧果汁加工厂的橙汁运输系统.系统有管道和节点构成.每条管道都是双向的,且每条管道的流量都 ...
- BZOJ 4435 [Cerc2015]Juice Junctions 分治最小割+hash
分治最小割的题目,要求n2. 之前用的n3的方法自然不能用了. 于是用hash,设hash[i][j]表示在最小割为i的时候,j是否与S联通. 看懂这个需要理解一下最小割树的构造. 这种题建议用EK写 ...
- BZOJ4435 : [Cerc2015]Juice Junctions
最大流=最小割,而因为本题点的度数不超过3,所以最小割不超过3,EK算法的复杂度为$O(n+m)$. 通过分治求出最小割树,设$f[i][j][k]$表示最小割为$i$时,$j$点在第$k$次分治过程 ...
- BZOJ4435——[Cerc2015]Juice Junctions
0.题目大意:求两点之间的最小割之和 1.分析:很明显,最小割树,我们发现这个题并不能用n^3的方法来求答案.. 所以我们记录下所有的边,然后把边从大到小排序,然后跑一边类似kruskal的东西,顺便 ...
- 【BZOJ-4435】Juice Junctions 最小割树(分治+最小割)+Hash
4435: [Cerc2015]Juice Junctions Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 20 Solved: 11[Submi ...
- HDU 3849 By Recognizing These Guys, We Find Social Networks Useful(双连通)
HDU 3849 By Recognizing These Guys, We Find Social Networks Useful pid=3849" target="_blan ...
- Juice Junctions
Juice Junctions 题目描述 你被雇佣升级一个旧果汁加工厂的橙汁运输系统.系统有管道和节点构成.每条管道都是双向的,且每条管道的流量都是11升每秒.管道可能连接节点,每个节点最多可以连接3 ...
- poj 3352 Road Construction【边双连通求最少加多少条边使图双连通&&缩点】
Road Construction Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10141 Accepted: 503 ...
随机推荐
- springmvc+mybatis的增删改查入门
先到官网了解mybatis的语法:https://mybatis.org/mybatis-3/zh/sqlmap-xml.html 前端用了thymeleaf和vue.js,效果图和demo地址:ht ...
- Java 之 文件过滤器
在学习过滤器之前,先来做一个案例. 题目:文件搜索,搜索 D:\java 目录中 .java 文件. 分析: 1. 目录搜索,无法判断多少级目录,使用递归,遍历所有目录 2. 遍历目录时,获取的子 ...
- MongoDB 创建数据库和查询数据
1.选择数据库 use test 2.创建用户 db.createUser({user:"test01",pwd:"12345",roles:[{role ...
- List集合和Set集合互转
List集合转成Set集合(如果List集合的元素有重复,转成Set集合就会去掉重复的数据,每条数据只保留一条) //List转化成Set List<String> list = new ...
- 前端框架开始学习Vue(二)
1 根据关键字实现数组的过滤 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- springboot系列(七) 项目热加载
spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot应用. devtool ...
- zookeeper服务【-】windows安装与liunx安装
windows安装zookeeper-3.4.14 https://www.apache.org/dyn/closer.cgi/zookeeper/ [zookeeper下载地址] 1.开启服务之前需 ...
- STL的sort函数是使用什么排序算法的?
先占坑,大概就是主要快速排序+插入排序+堆排序的合体
- windows平台RSA密钥生成
1.安装openssl工具 下载安装openssl工具,执行安装目录bin下的"openssl.exe",执行后会弹出命令窗口. 2.生成私钥 在命令窗口输入“genrsa -ou ...
- Parameter 0 of method redisTemplate in org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration required a bean of type 'org.springframework.data.redis.connection.RedisConnectionFactor
Error starting ApplicationContext. To display the conditions report re-run your application with 'de ...