A brief test instructions of the problem
and hdoj 30,621 samples
Here each member has the choice and does not choose two kinds, namely the last article said $x$ and $x ' $
Map: Captain (a) left or the remaining two players (b, c) remain
So that is $ A ' \rightarrow b$, $a ' \rightarrow C $ (captain not in B must be in, captain not in C must be in)
As well as $b ' \rightarrow a$, $c ' \rightarrow a$ (b not in captain must be in, C not captain must be in)
Each pair of players, if player a leaves, then player B must go home to rest, or b leave, a home
So that's $ A \rightarrow B ' $ (a in then B must be absent) as well as $B \rightarrow a ' $ (b in then a must not)
1#include <bits/stdc++.h>2 using namespacestd;3typedefLong LongLL;4typedef pair<int,int>PI;5 #defineINF 0x3f3f3f3f6 7 Const intn=3005*2;8 Const intm=n*N;9 //Note that n is the size after the split, i.e. n <<= 1 n is the number of points (note to double) m is the i&1=0 for I true i&1=1 for I falseTen structEdge One { A intto, NEX; - }edge[m]; - //Note N M to modify the intHead[n], edgenum; - voidAddedge (intUintv) - { -Edge e={V, head[u]}; +edge[edgenum]=E; -head[u]=edgenum++; + } A at BOOLMark[n]; - intStack[n], top; - voidInit () - { -Memset (Head,-1,sizeof(head)); -edgenum=0; inmemset (Mark,0,sizeof(Mark)); - } to + BOOLDfsintx) - { the if(mark[x^1]) * return false;//must be the point of the break first Judge $ if(Mark[x])Panax Notoginseng return true; -mark[x]=true; thestack[top++]=x; + for(inti=head[x];i!=-1; i=Edge[i].nex) A if(!DFS (edge[i].to)) the return false; + - return true; $ } $ - BOOLSolveintN) - { the for(intI=0; i<n;i+=2) - if(!mark[i] &&!mark[i^1])Wuyi { thetop=0; - if(!DFS (i)) Wu { - while(top) Aboutmark[stack[--top]]=false; $ if(!dfs (i^1)) - return false; - } - } A return true; + } the - intMain () $ { the intN, M; the while(~SCANF ("%d%d", &n, &m)) the { the intnn=n*3; - init (); in while(n--) the { the intA, B, C; Aboutscanf"%d%d%d", &a, &b, &c); theAddedge (A *2+1, b*2); theAddedge (A *2+1, c*2); theAddedge (b*2+1, A *2); +Addedge (c*2+1, A *2); - } the while(m--)Bayi { the intx, y; thescanf"%d%d", &x, &y); -Addedge (x*2, y*2+1); -Addedge (y*2, x*2+1); the } theSolve (NN)? Puts"Yes"): Puts ("No"); the } the return 0; -}hdoj 1824
[2-sat] HDOJ1824 let ' s go home