题解:
一定割一条树边,然后分类讨论即可。
注意两条被环覆盖的树边同时被删除合法当且仅当覆盖他们的环边集合相同,这个可以hash。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int RLEN=1<<18|1;
inline char nc() {
static char ibuf[RLEN],*ib,*ob;
(ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
char ch=nc(); int i=0,f=1;
while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
return i*f;
}
const int N=1e5+50;
int n,m,a[N<<2],b[N<<2],c[N],ind; LL ans;
int st[N],sze[N],son[N],top[N],fa[N],dep[N];
vector <int> edge[N];
vector <int> e[N];
inline void dfs(int x,int f) {
sze[x]=1; st[x]=++ind; fa[x]=f; dep[x]=dep[f]+1;
for(auto v:edge[x]) if(!st[v]) {
dfs(v,x); sze[x]+=sze[v];
e[x].push_back(v);
if(sze[son[x]]<sze[v]) son[x]=v;
}
}
inline void Dfs(int x,int f) {top[x]=f; for(auto v:e[x]) Dfs(v,(son[x]==v) ? f : v);}
inline int lca(int x,int y) {while(top[x]^top[y]) (dep[top[x]]>dep[top[y]]) ? (x=fa[top[x]]) : (y=fa[top[y]]); return (dep[x]<dep[y]) ? x : y;}
inline void dfs2(int x,int f) {for(auto v:e[x]) dfs2(v,x), c[x]+=c[v];}
map <int,int> s;
inline void dfs3(int x,int f) {for(auto v:e[x]) dfs3(v,x), c[x]^=c[v]; if(x!=1) ans+=s[c[x]]++;}
int main() {
n=rd(), m=rd(); srand(time(0));
for(int i=1;i<=m;i++) {
int x=a[i]=rd(), y=b[i]=rd();
edge[x].push_back(y);
edge[y].push_back(x);
} dfs(1,0); Dfs(1,1);
for(int i=1;i<=m;i++) {
int x=a[i], y=b[i];
if(fa[x]==y || fa[y]==x) continue;
int l=lca(x,y);
c[l]-=2; c[x]++; c[y]++;
} dfs2(1,0);
for(int i=2;i<=n;i++) if(!c[i]) ++ans;
ans=(LL)ans*(m-ans);
for(int i=2;i<=n;i++) if(c[i]==1) ++ans;
for(int i=1;i<=n;i++) c[i]=0;
for(int i=1;i<=m;i++) {
int x=a[i], y=b[i];
if(fa[x]==y || fa[y]==x) continue;
int l=lca(x,y), t=(rand()<<4)^rand();
c[x]^=t; c[y]^=t;
} dfs3(1,0);
cout<<ans<<'\n';
}