Friends

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 1717    Accepted Submission(s): 854

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
0
2
 
Author
XJZX
 
Source
 
Recommend
wange2014   |   We have carefully selected several similar problems for you:  5395 5394 5393 

pid=5392" target="_blank">5392 

pid=5391" target="_blank">5391 

 

暴搜

#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;
}

HDU 5305(Friends-暴搜)的更多相关文章

  1. hdu 1979 剪枝暴搜

    Fill the blanks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. HDU 4284 Travel (Folyd预处理+dfs暴搜)

    题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不 ...

  3. HDU 4620 Fruit Ninja Extreme 暴搜

    题目大意:题目就是描述的水果忍者. N表示以下共有 N种切水果的方式. M表示有M个水果需要你切. W表示两次连续连击之间最大的间隔时间. 然后下N行描述的是 N种切发 第一个数字C表示这种切法可以切 ...

  4. hdu 5952 Counting Cliques 求图中指定大小的团的个数 暴搜

    题目链接 题意 给定一个\(n个点,m条边\)的无向图,找出其中大小为\(s\)的完全图个数\((n\leq 100,m\leq 1000,s\leq 10)\). 思路 暴搜. 搜索的时候判断要加进 ...

  5. HDU - 6185 Covering(暴搜+递推+矩阵快速幂)

    Covering Bob's school has a big playground, boys and girls always play games here after school. To p ...

  6. hdu 4400 离散化+二分+BFS(暴搜剪枝还超时的时候可以借鉴一下)

    Mines Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  7. HDU4403(暴搜)

    A very hard Aoshu problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  8. 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜

    3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 154[Submit][Status][Discuss] ...

  9. c++20701除法(刘汝佳1、2册第七章,暴搜解决)

    20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有 ...

随机推荐

  1. Linux学习笔记之Linux命令

    1. blkid  查看当前系统中所有已挂载文件系统的类型

  2. Docker在Ubuntu16.04上安装

    转自:http://blog.51cto.com/collen7788/2047800 1.添加Docker源 sudo apt-get update 2.增加CA证书 sudo apt-get in ...

  3. C语言调用Python

    python模块:demo.py def print_arg(str): print str def add(a,b): print 'a=', a print 'b=', b return a + ...

  4. text-shadow的用法详解

    1.兼容性:text-shadow 和 box-shadow 这两个属性在主流现代浏览器上得到了很好的支持( > Chrome 4.0, > Firefox 3.5, > Safar ...

  5. windows server 2008 如何查看异常重启日志

    下面蓝队网络为大家介绍下windows server 2008 如何查看异常重启日志 开始->管理工具->时间查看器 windows日志->系统 筛选当前日志 选择Kernel-Po ...

  6. 音视频】5.ffmpeg命令分类与使用

    GT其实平时也有一些处理音视频的个人或者亲人需求,熟练使用ffmpeg之后也不要借助图示化软件,一个命令基本可以搞定 G: 熟练使用ffmpeg命令!T :不要死记硬背,看一遍,自己找下规律,敲一遍, ...

  7. cstring to utf8

    char* UnicodeToUtf8(CString unicode) { int len; len = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)unico ...

  8. 00JAVA EE

    JAVA EE 三层架构 我们的开发架构一般都是基于两种形式,一种是C/S架构,也就是客户端/服务器,另一种是B/S架构,也就是浏览器服务器.在JavaEE开发中,几乎全都是基于B/S架构的开发.那么 ...

  9. 04Oracle Database 登陆

    Oracle Database 登陆 EM Express Login https://localhost:5500/em/login cmd sqlplus SQL/PLUS system/code ...

  10. Install Zabbix with Docker

    1. mysql -uroot -p -h10.10.0.242 zabbix<schema.sqlEnter password: * ERROR 1709 (HY000) at line 86 ...