标签:
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 }
标签:
原文地址:http://www.cnblogs.com/cheater/p/4670199.html