Problem Description There is n people and m pairs of friends. For every pair of friends, they can choose to become online friends (communicating using online applications) or offline F Riends (mostly using face-to-face communication). However, everyone in these n people wants to having the same number of online and offline friends (i.e. If one person has X onine Friends, he or she must has X offline friends too, but different people can has different number of online or O Ffline friends). Determine how many ways there is to satisfy their requirements.
Input the first line of the input is a single integer T (t=100), indicating the number of testcases.
For each testcase, the first line contains the integers n (1≤n≤8) and M (0≤m≤n (n−1) 2), indicating the number of people a nd the number of pairs of friends, respectively. Each of the next m lines contains-numbers x and y, which mean X and Y are friends. It is guaranteed that x≠y and every friend relationship would appear at the most once.
Output for each testcase, print one number indicating the answer.
Sample Input
2 3 3 1 2 2 3 3 1 4 4 1 2 2 3 3 4 4 1
Sample Output
0 2
Author XJZX
Source multi-university Training Contest 2 test instructions: gives n points, M edge, n<=8,m<=n* (n-1)/2, all sides have 2 properties, Requires equal number of edges with two attributes per point ask how many scenarios to analyze: up to 28 edges, assuming that the attribute of the Edge is a, b then simply DFS enumerates the attributes of each edge (A or B.) and finally checks if the number of edges of two attributes per point is equal Pruning operation: 1. If a point has an odd number of edges, the answer is 0 2. If the edge of the a property of point X is already greater than or equal to the total number of edges of the point x, then X's Edge can no longer be an attribute (otherwise not a satisfactory scheme)
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <
algorithm> #include <queue> #define MEM (a,x) memset (A,x,sizeof (a)) using namespace Std;
typedef long Long LL;
const int inf = 1<<29;
const int N = 10; int a[n+5],b[n+5];//records the number of each point edge attribute vector<int>u[n+5];//records the edge struct edge {int u,v that each point owns;}
e[30];//first save the edge and finally enumerate int n,m;
ll ans;
BOOL OK ()//whether the number of edges for each of the two properties of the point is equal {for (int i = 1;i <= 8;++i) {if (A[i]!=b[i]) return 0;
} return 1;
} void Dfs (int p)//enumerates the properties of each edge {if (p = = m) {if (ok ())) ans++;
Return } int x = E[p].u,y = e[p].v;//Two points attached to this edge if (A[x] < U[x].size ()/2&&a[y] < U[y].size ()/2)//less than half {
This side is sentenced to a attribute a[x]++;
a[y]++;
DFS (p+1);//next Edge a[x]--;
a[y]--;
} if (B[x]<u[x].size ()/2&&b[y]<u[y].size ()/2) {b[x]++;
b[y]++; DFS (P+1);
b[x]--;
b[y]--;
}} int main () {int t;scanf ("%d", &t);
while (t--) {scanf ("%d%d", &n,&m);
for (int i = 1;i <= 8;++i) u[i].clear ();
for (int i = 0;i < M;++i) {scanf ("%d%d", &E[I].U,&E[I].V);
U[e[i].v].push_back (E[I].U);
U[e[i].u].push_back (E[I].V);
} bool fd = 0;
for (int i = 0;i <= 8;++i) {if (u[i].size ()%2)//odd {FD = 1;
Break
}} if (FD) {puts ("0");
Continue
} ans = 0;mem (a,0); mem (b,0);
DFS (0);
printf ("%lld\n", ans);
} return 0;
}