码迷,mamicode.com
首页 > 其他好文 > 详细

2015 多校

时间:2015-07-23 13:50:26      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

Friends

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


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 (1n8) and m (0mn(n1)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 xy 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
 
技术分享
 1 #include <cstdio>
 2 #include <cstring>
 3 
 4 
 5 int pu[100000000], pv[100000000];
 6 
 7 int white[10], black[10], deg[10];
 8 
 9 int p[30];
10 int t, n, m;
11 
12 int main() {
13     
14     for (int i = 1; i <= 28; i++) p[i] = 1 << i;
15     scanf("%d", &t);
16     while (t--) {
17         memset(deg, 0, sizeof(deg));
18         scanf("%d%d", &n, &m);
19         for (int i = 1; i <= m; i++) {
20             scanf("%d%d", &pu[i], &pv[i]);
21             deg[pu[i]]++;
22             deg[pv[i]]++;
23         }
24         bool ok = true;
25         for (int i = 1; i <= n; i++) {
26             if (deg[i]&1) {
27                 ok = false;
28                 break;
29             }
30         }
31         if (!ok) {
32             puts("0");
33             continue;
34         }
35         int maxlen = 1 << m;
36         int ans = 0;
37         for (int i = 0; i <= maxlen; i++) {
38             for (int j = 1; j <= m; j++) {
39                 if (i & p[j]) {
40                     black[pu[j]]++;
41                     black[pv[j]]++;
42                 } else {
43                     white[pu[j]]++;
44                     white[pv[j]]++;
45                 }
46             }
47             ok = true;
48             for (int i = 1; i <= n; i++) {
49                 if (black[i] != white[i]) {
50                     ok = false;
51                     break;
52                 }
53             }
54             if (ok) ans++;
55             memset(black, 0, sizeof(black));
56             memset(white, 0, sizeof(white));
57         }
58         printf("%d\n", ans);
59     }
60     return 0;
61 }
View Code

 

2015 多校

标签:

原文地址:http://www.cnblogs.com/cheater/p/4670199.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!