Problem Descriptionthere isNPeople andmPairs of friends. For every pair of friends, they can choose to become online friends (communicating using online applications) or offline F Riends (mostly using face-to-face communication). However, everyone in thesen people wants to has 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 has different Number of online or offline friends). Determine how many ways there is to satisfy their requirements.
Inputthe first line of the input was a single integerT (t=+) , indicating the number of testcases.
For each testcase, the first line contains the integersn (1≤n≤8) andm (0≤m≤< Span id= "mathjax-span-47" class= "Mi" >n ( n− 1) 2) , indicating the number of people and the number of pairs of friends, respectively. Each of the nextmLines contains, numbersxandy, which meanx and y are friends. It is guaranteed that x≠y and every friend relationship would appear at most ONC E.
Outputfor each testcase, print one number indicating the answer.
Sample Input23 31 22 33 14 41 22 33 44 1
Sample Output02
Test instructions: Give an image without a direction. The edges are dyed white or black in turn, so that the number of white and black edges associated with each point is the same. Ask how many methods of staining are available.
Ideas:
Search questions. Forced violence searches must be timed out. Enumeration points to search is also not good to write. So enumerate the edges.
Record the degree of each point, if a bit of degrees is odd, direct output 0. Otherwise, divide the degrees of all points by 2 to get the number of white edges associated with each point and the number of black edges, which is pruning.
The code is as follows:
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;intt,n,m,a[ -],b[ -],d[Ten];intb[ -],w[ -],ans;voidDfsintk) { if(k==m) {ans++;return; } intu=a[k],v=B[k]; if(b[u]<d[u]&&b[v]<D[v]) {B[u]++,b[v]++; DFS (k+1); B[u]--, b[v]--; } if(w[u]<d[u]&&w[v]<D[v]) {W[u]++,w[v]++; DFS (k+1); W[u]--, w[v]--; }}intMain () {scanf ("%d",&t); while(t--){ BOOLflag=true; scanf ("%d%d",&n,&m); memset (d,0,sizeof(d)); for(intI=0; i<m;i++) {scanf ("%d%d",&a[i],&B[i]); D[a[i]]+ +;d [b[i]]++; } for(intI=1; i<=n;i++){ if(d[i]&1) Flag=false; D[i]/=2; } if(!flag) {Puts ("0"); Continue; } memset (W,0,sizeof(W)); memset (B,0,sizeof(B)); Ans=0; DFS (0); printf ("%d\n", ans); } return 0;}
View Code
2015 Multi-school Race second game 1006 (Hdu 5305)