1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| #include<iostream> #include<cstdio> #include<vector> #define ll long long using namespace std; const int N=5e5+10,M=1e6+10,mod=1e9+7; template<class T> inline void read(T &x) { x=0;int f=0; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();} while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); if(f)x=~x+1; } template<class T,class ...T1> inline void read(T &x,T1 &...x1) { read(x),read(x1...); } int n,m; int tot=1,head[N],ver[M<<1],ne[M<<1]; int num,dfn[N],low[N],bri[M<<1]; int cnt,c[N]; int a[N],b[N],sum[N]; ll f[N],ans,p[N+M]; vector<int>e[N]; inline void add(int u,int v) { ver[++tot]=v; ne[tot]=head[u]; head[u]=tot; } void Tarjan(int x,int pre) { dfn[x]=low[x]=++num; for(int i=head[x];i;i=ne[i]) { int y=ver[i]; if(!dfn[y]) { Tarjan(y,i); low[x]=min(low[x],low[y]); if(dfn[x]<low[y]) bri[i]=bri[i^1]=1; } else if(i!=(pre^1)) low[x]=min(low[x],dfn[y]); } } void prework(int x) { c[x]=cnt; a[cnt]++; for(int i=head[x];i;i=ne[i]) { int y=ver[i]; if(!c[y]&&!bri[i]) prework(y); } } void dfs(int x,int fa) { f[x]=p[a[x]+b[x]]%mod; sum[x]=b[x]; for(auto y:e[x]) { if(y==fa)continue; dfs(y,x); sum[x]+=sum[y]+1; f[x]=f[x]*((f[y]+p[sum[y]+1])%mod)%mod; } f[x]=(f[x]+mod-p[sum[x]])%mod; ans=(ans+f[x]*p[m-sum[x]-(fa!=0)]%mod)%mod; } int main() { read(n,m); for(int i=1;i<=m;i++) { int u,v; read(u,v); add(u,v); add(v,u); } Tarjan(1,0); for(int i=1;i<=n;i++) if(!c[i]) cnt++,prework(i); for(int x=1;x<=n;x++) { for(int i=head[x];i;i=ne[i]) { int y=ver[i]; if(c[x]==c[y])b[c[x]]++; else e[c[x]].push_back(c[y]); } } for(int i=1;i<=cnt;i++) b[i]/=2; p[0]=1; for(int i=1;i<=n+m;i++) p[i]=(p[i-1]<<1)%mod; dfs(1,0); printf("%lld\n",ans%mod); return 0; }
|