多校 hdu 5305
来源:互联网 发布:手机翻牆软件 编辑:程序博客网 时间:2024/06/06 09:52
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 integersn (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.
For each testcase, the first line contains two integers
Output
For each testcase, print one number indicating the answer.
Sample Input
23 31 22 33 14 41 22 33 44 1
Sample Output
02
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 10int 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;}
1 0
- 多校 hdu 5305
- hdu 5305
- HDU 5305
- hdu 多校
- hdu 多校
- 多校 hdu
- 多校 hdu
- 多校 hdu
- HDU 多校
- [多校2015.02.1006 高斯消元] hdu 5305 Friends
- 2015 多校(1) HDU 5288 HDU 5289
- HDU 5305 Friends (DFS)
- hdu 5305 Friends
- HDU 5305 Friends (DFS)
- hdu 5305 Friends 【暴搜】
- hdu 5305 friends
- HDU 5305 Friends
- HDU 5305 Friends
- google protocol buffer (C++,Java序列化使用实例)
- Mia_PDF_Tool v1.0 工具软件使用说明
- 判断一个字符串是否为数字
- oracle表分区详解
- 高并发量网站解决方案
- 多校 hdu 5305
- Android GUI之View测量
- linux 之 mysql问题
- jdbc连接oracle10g测试数据库插入
- 深入理解javascript之函数
- 南邮 OJ 1061 简单选择排序
- 欢迎使用CSDN-markdown编辑器
- 边框宽度 border-width
- JS学习2--关于预解释