HDU 5305 Friends (Simple Dfs)

Source: Internet
Author: User

FriendsTime limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 878 Accepted Submission (s): 422


Problem Descriptionthere is 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 F Riends (mostly using face-to-face communication). However, everyone in these n People wants to having 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 integer t (t=+) , indicating the number of testcases.

For each testcase, the first line contains the integers < Span class= "Mrow" id= "mathjax-span-26" style= "" >n &NBSP; ( 1 ≤ n ≤ 8 ) Span style= "" > 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, numbers x and y , which mean x and y Is friends. It's Guaranteed that x≠y And every friend relationship would appear at the most once.

Outputfor each testcase, print one number indicating the answer.
Sample Input
23 31 22 33 14 41 22 33 44 1

Sample Output
02

Source2015 multi-university Training Contest 2


Test Instructions: n individuals, respectively, have their own friends, some good relations, some bad relations, now ask everyone's friends in good relationship with the number of bad relations, ask how many options? thinking: Because the need for good relationship with the number of bad relationship is the same, so the number of friends is odd can be directly output 0, (because there is no way to make the same number of odd), after the odd number of search, first find out the relationship between friends, the rest of the automatic relationship between the bad, if there are two people have a good friend and bad friend has been full, direct return, a time-saving place.
when the game was made, the team did not look at the search, ah ah ah ah ah



#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <    Stdlib.h>using namespace Std;int n,m;int num[10];int pa[10],pb[10];int sum;struct node{int x; int y;}   q[100100];void DFS (int p) {//printf ("p =%d\n", p);       if (p = = m) {sum++;   return;   } int x = q[p].x;   int y = q[p].y;       if (Pa[x] && pa[y]) {pa[x]--;       pa[y]--;       DFS (p+1);       pa[x]++;   pa[y]++;       } if (Pb[x] && pb[y]) {pb[x]--;       pb[y]--;       DFS (p+1);       pb[x]++;   pb[y]++; } return;    int main () {int T;    scanf ("%d", &t);        while (t--) {sum = 0;        memset (num,0,sizeof (num));        scanf ("%d%d", &n,&m);        int x, y;            for (int i=0;i<m;i++) {scanf ("%d%d", &x,&y);            q[i].x = x;            Q[i].y = y;            num[x]++;        num[y]++;        } int flag = 0; for (int i=1;i<=n;i++) {           Pa[i] = NUM[I]/2;            Pb[i] = NUM[I]/2;                if (num[i]%2 = = 1) {flag = 1;            Break            }} if (flag) {printf ("0\n");        Continue        } DFS (0);    printf ("%d\n", sum); } return 0;}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 5305 Friends (Simple Dfs)

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.