• [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
    ",ans);
    	return 0;
    }
    
  • 相关阅读:
    hadoop入门学习系列之一hadoop伪分布式模式下安装及运行
    redis主从复制搭建
    Struts2 配置文件result的name属性和type属性
    context:exclude-filter spring事宜【经典-转】
    Incorrect column count: expected 1, actual 2
    SQL must not be null(低级错误)
    Injection of resource dependencies failed解决办法总结
    SpringMVC Controller 介绍【转】
    Json格式化工具 JsonViewer下载
    STS或eclipse安装SVN插件
  • 原文地址:https://www.cnblogs.com/y2823774827y/p/10952510.html
Copyright © 2020-2023  润新知