Test instructions
There are n people m to friends, friends have two kinds of online, a face to the face. Now let's make arrangements for the nature of these friends so that each person's online friends and the number of offline friends are the same, and the number of programs to be satisfied.
Ideas
Direct violence staining.
Then minus the sticks.
One is that for each person the degree must be an even number.
Another is staining, for a node can not be dyed more than half to continue Dfs.
Reference code:
/ * #pragma warning (disable:4786) #pragma comment (linker, "/stack:0x800000") */#include <cassert>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <sstream>#include <iomanip>#include <string>#include <vector>#include <list>#include <set>#include <map>#include <stack>#include <queue>#include <algorithm>#include <iterator>#include <utility>using namespace STD;Template<classT > t _abs (t N) {return(N <0? -N:N);}Template<classT > t _max (t A, T b) {return(! (A < b)? A:B);}Template<classT > t _min (t A, T b) {return(A < b? a:b);}Template<classT > t sq (t x) {returnx * x;}Template<classT > t gcd (t A, T b) {return(b! =0? Gcd<t> (b, a%b): a);}Template<classT > t LCM (t A, T b) {return(A/gcd<t> (A, b) * b);}Template<classT >BOOLInside (t A, T B, t C) {returnA<=b && B<=c;}#define MIN (A, B) ((a) < (b)? (a): (b))#define MAX (A, B) ((a) > (b)? (a): (b))#define F (i, n) for (int (i) =0; (i) < (n); + + (i))#define REP (i, S, T) for (int (i) = (s);(i) <= (t); + + (i))#define UREP (i, S, T) for (int (i) = (s);(i) >= (t);--(i))#define REPOK (i, S, T, O) for (int (i) = (s);(i) <= (t) && (o); + + (i))#define MEM0 (addr) memset ((addr), 0, sizeof ((addr)))#define MP (x, y) make_pair (x, y)#define REV (S, e) reverse (S, e )#define SET (P) memset (pair,-1, sizeof (p))#define CLR (P) memset (p, 0, sizeof (p))#define MEM (P, v) memset (P, V, sizeof (p))#define CPY (d, s) memcpy (d, S, sizeof (s))#define READ (f) freopen (F, "R", stdin)#define WRITE (f) freopen (F, "w", stdout)#define SZ (c) (int) c.size ()#define PB (x) push_back (x)#define FF First#define SS Second#define LL Long Long#define LD long double#define PII pair< int, int >#define PSI pair< string, int >#define LS u << 1#define RS u << 1 | 1#define Lson L, Mid, U << 1#define Rson Mid, R, u << 1 | 1Const intMAXN = -;Const intMaxnum =100010;Const intINF =0x3f3f3f3f;Const DoubleEPS =1e-9;using namespace STD;intM,n,ans;intX[MAXN],Y[MAXN],S[MAXN],S1[MAXN],S2[MAXN],G[MAXN][MAXN];voidDfsintDEP) {if(Dep > m) {Rep (I,1, N) {if(S1[i]! = S2[i])return; } ans++;return; }intU = X[DEP];intv = Y[DEP];if(S1[u] < s[u]/2&& S1[v] < s[v]/2) {s1[u]++;s1[v]++; DFS (dep+1); s1[u]--;s1[v]--; }if(S2[u] < s[u]/2&& S2[v] < s[v]/2) {s2[u]++;s2[v]++; DFS (dep+1); s2[u]--;s2[v]--; }}intMain () {//read ("In.txt"); intTscanf("%d", &t); while(t--) {scanf("%d%d", &n,&m); MEM0 (G); Rep (I,1, m) {scanf("%d%d", &x[i],&y[i]); G[x[i]][y[i]] = g[y[i]][x[i]] =1; }intFlag =1; Rep (I,1, n) {s[i] = s1[i] = S2[i] =0; Rep (J,1, N) {if(I! = J && g[i][j] = =1) s[i]++; }if(S[i] &1) flag =0; }if(!flag) {printf("0\n");Continue; } ans =0; Dfs1);printf("%d\n", ans); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdu 5305 (burst + two staining) Friends