2 3 3 1 2 2 3 3 1 4 4 1 2 2 3 3 4 4 1
0 2
暴搜
#include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<functional> #include<iostream> #include<cmath> #include<cctype> #include<ctime> using namespace std; #define For(i,n) for(int i=1;i<=n;i++) #define Fork(i,k,n) for(int i=k;i<=n;i++) #define Rep(i,n) for(int i=0;i<n;i++) #define ForD(i,n) for(int i=n;i;i--) #define RepD(i,n) for(int i=n;i>=0;i--) #define Forp(x) for(int p=pre[x];p;p=next[p]) #define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1) #define Rson ((x<<1)+1) #define MEM(a) memset(a,0,sizeof(a)); #define MEMI(a) memset(a,127,sizeof(a)); #define MEMi(a) memset(a,128,sizeof(a)); #define INF (2139062143) #define F (100000007) #define MAXN (100+10) #define MAXM (100+10) typedef long long ll; ll mul(ll a,ll b){return (a*b)%F;} ll add(ll a,ll b){return (a+b)%F;} ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;} void upd(ll &a,ll b){a=(a%F+b%F)%F;} int n,m; int e[MAXM][2]; int degree[MAXN],totdeg[MAXN]; ll ans; bool check(int x,int y) { return ( ( totdeg[x]||( !degree[x] )) && ( totdeg[y]||( !degree[y] )) ); } void dfs(int p) { if (p==m) { For(i,n) if (i!=e[p][0]&&i!=e[p][1]&°ree[i]) return ; if (degree[e[p][0]]==degree[e[p][1]]&&abs(degree[e[p][0]])==1) { ans++; } return ; } // if (p==m+1) // { // ans++; // return; // } int x=e[p][0],y=e[p][1]; totdeg[x]--;totdeg[y]--; degree[x]++;degree[y]++; if (check(x,y)) dfs(p+1); degree[x]-=2;degree[y]-=2; if (check(x,y)) dfs(p+1); degree[x]++;degree[y]++; totdeg[x]++;totdeg[y]++; } int main() { // freopen("F.in","r",stdin); int T;cin>>T; while(T--) { ans=0; MEM(degree) MEM(totdeg) cin>>n>>m; For(i,m) scanf("%d%d",&e[i][0],&e[i][1]),totdeg[e[i][0]]++,totdeg[e[i][1]]++; bool flag=0; For(i,n) if (totdeg[i] & 1) { flag=1;puts("0");break; } if (flag) continue; if (m) dfs(1); else ans=1; printf("%lld\n",ans); } return 0; }