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
|
#include<bits/stdc++.h> #include<bits/extc++.h> #define re register typedef long long ll; template<class T> inline void read(T &x) { x=0; char ch=getchar(),t=0; while(ch<'0'||ch>'9') t|=ch=='-',ch=getchar(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); if(t) x=-x; } template<class T,class ...T1> inline void read(T &x,T1 &...x1){ read(x),read(x1...); } template<class T> inline void write(T x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } template<> inline void write(bool x){ putchar(x?'1':'0'); } template<> inline void write(char c){ putchar(c); } template<> inline void write(char *s){ while(*s!='\0') putchar(*s++); } template<> inline void write(const char *s){ while(*s!='\0') putchar(*s++); } template<class T,class ...T1> inline void write(T x,T1 ...x1){ write(x),write(x1...); } template<class T> inline bool checkMax(T &x,T y){ return x<y?x=y,1:0; } template<class T> inline bool checkMin(T &x,T y){ return x>y?x=y,1:0; } using Pir=std::pair<int,int>; #define fir first #define sec second #define Mkr std::make_pair const int MAXN=1e6+10; const int Mod=1e9+7; template<class T> inline void add(T &x,T y){ x=x+y>=Mod?x+y-Mod:x+y; } int N,M,C,Num,Pw[MAXN]; ll val[MAXN],rd[MAXN],ans; bool Vis[MAXN]; std::vector<Pir>Edges[MAXN]; std::mt19937_64 rnd((ll)new char); std::unordered_map<ll,int>Hash; void dfsTree(int x,int fe) { Vis[x]=1; for(auto p:Edges[x]) { int v=p.fir,id=p.sec; if(id==fe) continue; if(!Vis[v]) dfsTree(v,id),val[id]=rd[v],rd[x]^=rd[v]; else if(!val[id]) val[id]=rnd(),rd[x]^=val[id],rd[v]^=val[id]; } } int main() { read(N,M),Pw[0]=1;Hash.clear(); for(int i=1,u,v;i<=M;++i) { read(u,v);Pw[i]=(Pw[i-1]<<1)%Mod; Edges[u].push_back(Mkr(v,i)); Edges[v].push_back(Mkr(u,i)); } for(int x=1;x<=N;++x) if(!Vis[x]) dfsTree(x,0),++C; for(int i=1;i<=M;++i) if(val[i]) ++Num,++Hash[val[i]]; for(auto p:Hash) { add(ans,(ll)p.sec*p.sec%Mod*Pw[(M-2)-N+(C+1)]%Mod); add(ans,(ll)p.sec*(Num-p.sec)%Mod*Pw[(M-2)-N+C]%Mod); } write(ans); return 0; }
|