Problem Description
There are
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 friends (mostly using face-to-face communication). However, everyone in these
n people wants to have the same number of online and offline friends (i.e. If one person has
x onine friends, he or she must have
x offline friends too, but different people can have different number of online or offline friends). Please determine how many ways there are 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 two integers
n (1≤n≤8) and
m (0≤m≤n(n−1)2) , indicating the number of people and the number of pairs of friends, respectively. Each of the next
m lines contains two numbers
x and
y , which mean
x and
y are friends. It is guaranteed that
x≠y and every friend relationship will appear at 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
Author
XJZX
Source
2015 Multi-University Training Contest 2
唔。。。这次题目没读错,可是不会-_-/// 朋友分为线上好友和线下好友 给定若干人和朋友关系 问有多少种分配方式保证每个人的两种好友一样多
据说这个相当于给边染色@.@ 深搜 omg 五个数组 某边入度点 in[i] ;某边出度点 out[i] ;某点的度 de[i] ;白色边on[i] 黑色边 off[i] 开头剪枝一次就够了==
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int m,n,ans;
int in[100],out[100],de[100],on[100],off[100];
void dfs(int u)
{
if(u==m+1)
{
for(int i=1;i<=n;i++)
if(on[i]!=off[i]) return;
ans++;
return;
}
if(on[in[u]]<de[in[u]]/2&&on[out[u]]<de[out[u]]/2)
{
on[in[u]]++;on[out[u]]++;
dfs(u+1);
on[in[u]]--;on[out[u]]--;
}
if(off[in[u]]<de[in[u]]/2&&off[out[u]]<de[out[u]]/2)
{
off[in[u]]++;off[out[u]]++;
dfs(u+1);
off[in[u]]--;off[out[u]]--;
}
}
int main()
{
// freopen("cin.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
memset(de,0,sizeof(de));
memset(on,0,sizeof(on));
memset(off,0,sizeof(off));
for(int i=1;i<=m;i++)
{
scanf("%d%d",&in[i],&out[i]);
de[in[i]]++;de[out[i]]++;
}
int flag=1;
for(int i=1;i<=n;i++)
{
if(de[i]%2==1) {printf("0\n");flag=0;break;}
}
if(!flag) continue;
ans=0;
dfs(1);
printf("%d\n",ans);
}
return 0;
}