先把一个环缩成一个点处理
然后转化成树形dp解决即可
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1000010;
const int mod=19260817;
int num[N],low[N];
int ring[N],stk[N];
int belong[N];
int ins[N];
int id,top,scc;
vector<int>e[N];
vector<int>e2[N];
ll f[N];
ll res;
struct node{
int x,y;
}edge[2*N];
void dfs(int u,int fa){
stk[++top]=u;
id++;
num[u]=low[u]=id;
ins[u]=1;
for(int i=0;i<(int)e[u].size();i++){
int v=e[u][i];
if(v==fa)continue;
if(num[v]==0){
dfs(v,u);
low[u]=min(low[u],low[v]);
}
else if(ins[v]){
low[u]=min(low[u],num[v]);
}
}
if(num[u]==low[u]){
scc++;
while(top){
int v=stk[top--];
ring[scc]++;
belong[v]=scc;
ins[v]=0;
if(v==u)break;
}
}
}
void dfs_dp(int u,int fa){
ll tmp=0;
if(ring[u]>1)f[u]=1;
for(int i=0;i<(int)e2[u].size();i++){
int v=e2[u][i];
if(v==fa)continue;
dfs_dp(v,u);
tmp+=f[u]*f[v]%mod;
if(ring[u]>1)f[u]=(f[u]+f[v]*2)%mod;
else f[u]=(f[u]+f[v])%mod;
}
res=(res+tmp)%mod;
}
int main(){
// freopen("1.txt","r",stdin);
int n,m;
cin>>n>>m;
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
e[x].push_back(y);
e[y].push_back(x);
edge[i]={x,y};
}
dfs(1,0);
for(int i=1;i<=m;i++){
int u=belong[edge[i].x];
int v=belong[edge[i].y];
if(u==v)continue;
e2[u].push_back(v);
e2[v].push_back(u);
}
dfs_dp(1,0);
cout<<res;
return 0;
}