数学题
首先有两种不合法的情况,度数>2,有环
最后每有一个点数>=2的联通快ans*=2,最后再乘个联通快个数
/**************************************************************
Problem: 3444
User: syh0313
Language: C++
Result: Accepted
Time:4512 ms
Memory:85588 kb
****************************************************************/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
using
namespace
std;
const
int
maxn=500010;
const
int
mo=989381;
int
n,m,st[maxn<<1],to[maxn<<1],nt[maxn<<1],topt,num,nn,in[maxn];
long
long
ans=1,p[maxn];
bool
ff,f[maxn];
map<
int
,
bool
>mp[maxn];
void
add(
int
x,
int
y)
{to[++topt]=y; nt[topt]=st[x]; st[x]=topt;}
void
dfs(
int
x,
int
fa)
{
if
(ff)
return
;
f[x]=1; num++;
int
pp=st[x];
while
(pp)
{
if
(!f[to[pp]]) dfs(to[pp],x);
else
if
(to[pp]!=fa) ff=1;
pp=nt[pp];
}
}
void
init(){p[0]=1;
for
(
int
i=1;i<=n;i++) p[i]=p[i-1]*i%mo;}
int
main()
{
scanf
(
"%d%d"
,&n,&m); init();
for
(
int
i=1;i<=m;i++)
{
int
xx,yy;
scanf
(
"%d%d"
,&xx,&yy);
if
(!mp[xx][yy])
{
add(xx,yy); add(yy,xx);
mp[xx][yy]=1; mp[yy][xx]=1;
if
(++in[xx]>=3) ff=1;
if
(++in[yy]>=3) ff=1;
}
}
if
(ff) {
printf
(
"0\n"
);
return
0;}
for
(
int
i=1;i<=n && !ff;i++)
if
(!f[i]) {num=0; dfs(i,i);
if
(num>=2) ans=2ll*ans%mo; nn++;}
if
(ff) {
printf
(
"0\n"
);
return
0;}
ans=ans*p[nn]%mo;
printf
(
"%lld\n"
,ans);
return
0;
}