zoukankan      html  css  js  c++  java
  • 黑魔*之门

    https://www.zybuluo.com/ysner/note/1239406

    题面

    给出一个大小为(n)的无向图,求图中每个点的度数大于零且都是偶数的子图的个数。

    • (nleq2*10^5)

    解析

    子图不一定是联通的!!!
    则设图中最小环(不由其它环组成的环)的个数为(x)
    如果同一联通块中的点再次联通,就构成了一个新的最小环。
    因为这些环选与不选都可构成新子图,于是
    (ans=2^x-1)(去掉一个环都不选的情况)。

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<vector>
    #define re register
    #define il inline
    #define ll long long
    #define max(a,b) ((a)>(b)?(a):(b))
    #define min(a,b) ((a)<(b)?(a):(b))
    #define fp(i,a,b) for(re int i=a;i<=b;i++)
    #define fq(i,a,b) for(re int i=a;i>=b;i--)
    using namespace std;
    const int mod=1e9+9,N=1e6+100;
    ll n,m,h[N],cnt,f[N],ans;
    il ll gi()
    {
       re ll x=0,t=1;
       re char ch=getchar();
       while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
       if(ch=='-') t=-1,ch=getchar();
       while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
       return x*t;
    }
    il int find(re int x){return x==f[x]?x:f[x]=find(f[x]);}
    int main()
    {
      freopen("magician.in","r",stdin);
      freopen("magician.out","w",stdout);
      n=gi();m=gi();
      fp(i,1,n) f[i]=i;
      fp(i,1,m)
        {
          re int u=gi(),v=gi(),fu=find(u),fv=find(v);
          if(fu^fv) f[fu]=fv;
          else ans=(ans*2+1)%mod;
          printf("%lld
    ",ans);
        }
      fclose(stdin);
      fclose(stdout);
      return 0;
    }
    
  • 相关阅读:
    C#中remoting和webservice的区别
    Nhibernate了解(转载)
    深入浅出JSON
    Asp.net页面传值总结(转载)
    .Net ViewState的实现(转载)
    asp.net数据绑定之Eval和Bind区别
    PetShop数据库解读
    .Net 2.0 缓存使用(转载)
    ASP.NET中EVAL用法大全
    a:hover和a:visited书写顺序的重要性
  • 原文地址:https://www.cnblogs.com/yanshannan/p/9426984.html
Copyright © 2011-2022 走看看