# 生成树

## 题解

https://blog.csdn.net/C20181220_xiang_m_y/article/details/107006724

$G$删掉一条边后是仙人掌，那么$G$一定是这样的形式：

$cnt*(\prod siz_i)+(\sum {l_i*r_i\over siz_i})*(\prod siz_i)$

CO int N=5e5+10;
int inv[N];
pair<int,int> edge[N];

}

int pos[N],low[N],tim,stk[2*N],top;
int dep[N],deg[N],dis[N],num;
vector<int> scc[N],big;
int id,ban[N],onc[N];

void tarjan(int x,int fa){
pos[x]=low[x]=++tim,stk[++top]=x;
int y=to[i];
if(!pos[y]){
stk[++top]=-i,dep[y]=dep[x]+1;
tarjan(y,i);
low[x]=min(low[x],low[y]);
if(low[y]==pos[x]){
scc[++num]={x};
int e=0;
for(int t=0;t!=-i;){
t=stk[top--];
if(t<0) ++e;
else{
scc[num].push_back(t);
if(deg[t]>2) dis[num]=dep[t]-dep[x];
}
}
if(e>(int)scc[num].size()) id=num;
}
else if(low[y]>pos[x]) top-=2; // -i and y
}
else if(pos[y]<pos[x])
stk[++top]=-i,low[x]=min(low[x],pos[y]);
}
}

int main(){
inv[0]=inv[1]=1;
for(int i=2;i<=n;++i) inv[i]=mul(mod-mod/i,inv[mod%i]);
for(int i=1;i<=m;++i){
}
tarjan(1,0);
int prod=1;
for(int i=1;i<=num;++i)if(i!=id) prod=mul(prod,scc[i].size());
if(!id){
printf("%d\n",prod);
return 0;
}
big=scc[id];
for(int x:big) onc[x]=1;
int all=0;
for(int i=1;i<=m;++i){
int x=edge[i].first,y=edge[i].second;
if(onc[x] and onc[y])
}
for(int x:big)if(deg[x]==3){
ban[i/2]=1;
fill(pos+1,pos+n+1,0),dep[x]=0,top=tim=num=id=0;
tarjan(x,0);
if(id) {ban[i/2]=0; continue;}
int cnt=0,pwr=1,sum=0;
for(int j=1;j<=num;++j){
pwr=mul(pwr,scc[j].size()),cnt+=scc[j].size();