标签:splay 多少 return http closed font code 联通 很多
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N=1000010,mod=998244353; 4 char gc(){ 5 static char*p1,*p2,s[1000000]; 6 if(p1==p2)p2=(p1=s)+fread(s,1,1000000,stdin); 7 return(p1==p2)?EOF:*p1++; 8 } 9 int rd(){ 10 int x=0;char c=gc(); 11 while(c<‘0‘||c>‘9‘)c=gc(); 12 while(c>=‘0‘&&c<=‘9‘)x=(x<<1)+(x<<3)+c-‘0‘,c=gc(); 13 return x; 14 } 15 int T,n,m,vis[N],bl[N],dfn[N],low[N],idx,fg,ans,st[N],top,o,hd[N],cnt,f[N],g[N],h[N],d[N]; 16 struct Edge{int v,nt;}E[N<<1]; 17 inline void adde(int u,int v){ 18 E[o]=(Edge){v,hd[u]};hd[u]=o++; 19 E[o]=(Edge){u,hd[v]};hd[v]=o++; 20 } 21 void tarjan(int u,int fa){ 22 if(fg)return; 23 dfn[st[++top]=u]=low[u]=++idx; 24 int tot=0; 25 for(int i=hd[u],v;i;i=E[i].nt){ 26 v=E[i].v; 27 if(v==fa)continue; 28 if(dfn[v=E[i].v]){ 29 if(d[v])continue; 30 if(dfn[v]<dfn[u]&&tot++){fg=1;break;} 31 low[u]=min(low[u],dfn[v]); 32 }else{ 33 tarjan(v,u); 34 if(low[v]<dfn[u]&&tot++){fg=1;break;} 35 low[u]=min(low[u],low[v]); 36 } 37 } 38 if(dfn[u]==low[u]){ 39 int v;++cnt; 40 do{bl[v=st[top--]]=cnt;d[v]=1;}while(v!=u); 41 } 42 } 43 void dfs(int u){ 44 f[u]=g[u]=vis[u]=1; 45 int tot=0; 46 for(int i=hd[u];i;i=E[i].nt){ 47 int v=E[i].v; 48 if(vis[v]||bl[v]==bl[u])continue; 49 tot++; 50 dfs(v); 51 f[u]=1ll*f[u]*g[v]%mod; 52 g[u]=1ll*g[u]*g[v]%mod; 53 } 54 f[u]=1ll*f[u]*h[tot]%mod; 55 g[u]=1ll*g[u]*h[tot+1]%mod; 56 } 57 int main(){ 58 #ifndef ONLINE_JUDGE 59 freopen("T1.in","r",stdin); 60 freopen("T1.out","w",stdout); 61 #endif 62 T=rd(); 63 h[0]=h[1]=1; 64 for(int i=2;i<=500001;++i)h[i]=(h[i-1]+1ll*(i-1)*h[i-2]%mod)%mod; 65 while(T--){ 66 n=rd();m=rd(); 67 fg=idx=cnt=top=0;ans=o=1; 68 for(int i=1;i<=n;++i)vis[i]=hd[i]=dfn[i]=d[i]=low[i]=0; 69 for(int i=1;i<=m;++i)adde(rd(),rd()); 70 tarjan(1,0); 71 if(fg){puts("0");continue;} 72 for(int i=1;i<=n;++i)if(!vis[i]){ 73 dfs(i); 74 ans = 1ll * ans * f[i]%mod; 75 } 76 printf("%d\n",ans); 77 } 78 return 0; 79 }
标签:splay 多少 return http closed font code 联通 很多
原文地址:https://www.cnblogs.com/Paul-Guderian/p/10306388.html