多校 hdu 5305
2015-08-04 10:08
211 查看
Friends
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1429 Accepted Submission(s): 725
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
2015 Multi-University Training Contest 2
#include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef pair<int , int > P; #define maxn 10 int num[maxn], g1[maxn], g2[maxn], n, m, T; P e[30]; int sum; void dfs(int t) { if(t == m + 1) { sum++; return ; } int u = e[t].first; int v = e[t].second; if(g1[u] && g1[v])// online { g1[u]--, g1[v]--; dfs(t + 1); g1[u]++, g1[v]++; } if(g2[u] && g2[v])// offline { g2[u]--, g2[v]--; dfs(t + 1); g2[u]++, g2[v]++; } return ; } int main() { scanf("%d", &T); while(T--) { memset(num, 0, sizeof num); memset(g1, 0, sizeof g1); memset(g2, 0, sizeof g2); int flag = 1; scanf("%d%d", &n, &m); int u, v; for(int i=1; i<=m; i++) { scanf("%d%d", &u, &v); e[i] = {u, v}; num[u]++; num[v]++; } for(int i=1; i<=n; i++) { if(num[i] & 1) { flag = 0; break; } num[i] >>= 1; g1[i] = g2[i] = num[i]; } sum = 0; dfs(1); if(flag) printf("%d\n", sum); else printf("0\n"); } return 0; }
相关文章推荐
- linux 之 mysql问题
- darwin转发时,摄像机在3G和4G模式下的参数设置
- objective-c中的方法重载
- google protocol buffer (C++,Java序列化使用实例)
- 关于C语言中二级指针的理解
- Android学习心得(10) --- MAC下Android反编译(2)
- Visual Studio 2015 速递(4)——高级特性之移动开发
- jQuery左侧图片右侧文字滑动切换代码
- This is python
- 南邮 OJ 1060 接苹果
- 工厂方法模式-Factory Pattern
- lvs、haproxy、nginx 负载均衡的比较分析
- 如何在 Ubuntu 上比较 PDF 文件
- Web Service修炼之二Xfire+Spring
- bc第八场Reading comprehension(快速幂,数模公式)
- MapReduce实现计数
- 阿里巴巴影业面试总结
- 用例规约
- Linux防火墙Iptables设置
- Apache Traffic Server 简介