HDU 5305 Friends (dfs)

Source: Internet
Author: User

HDU 5305 Friends (dfs)

 

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



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
23 31 22 33 14 41 22 33 44 1

Sample Output
02

Source

 

 

 

 

 

/* Question: n people, m relationships, and the relationship between each person and others are both wired and offline. I 'd like to ask everyone for a solution with the same relationship between online and offline: dfs first post others' code, fast Running, slow running */# include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
# Include
     
      
# Include
      
        # Include
       
         # Include
        
          # Include
         # Define L (x) (x <1) # define R (x) (x <1 | 1) # define MID (x, y) (x + y)> 1) # define eps 1e-8using namespace std; typedef _ int64 LL; # define N 100int x [N], y [N], in [N], on [N], off [N]; int n, m; int ans; bool judge () {if (m & 1) return false; for (int I = 1; I <= n; I ++) if (in [I] & 1) return false; return true;} void dfs (int pos) {if (pos = m) {ans ++; return;} int u = x [pos], v = y [pos]; if (on [u]
          
           

 

 

/* My Code */# include
            
             
# Include
             
              
# Include
              
               
# Include
               
                
# Include
                
                 
# Include
                 
                   # Include
                  
                    # Include
                   
                     # Include
                    # Define L (x) (x <1) # define R (x) (x <1 | 1) # define MID (x, y) (x + y)> 1) # define bug printf (hihi) # define eps 1e-8typedef _ int64 ll; using namespace std; # define INF 0x3f3f3f # define N 1 <8 _ int64 ans; int on [N], down [N]; int n, m, f [N], in [N]; inline int get (int x) {int s = 0; while (x) {s ++; x & = (x-1) ;}return s ;} inline bool judge (int pos, int cur) {int I; for (I = 0; I
                     
                      

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.