The main idea: when I was a child, homesickness was a small stamp, and I was in the head, and my mother was there.
--Yu Guangzhong
Training is hard, the road is bumpy, rest is necessary. After a period of training, LCY decided to let everyone go home to relax, but the training is still going on, LCY came up with the following home rules, each team (three people a team) or the captain left or the remaining two players left at the same time; each pair of players, if player a leaves, then team B must go home to rest, or b leave , a go home. As the number of training team this year to break through the highest record of previous years, management difficulty is quite large, LCY also do not know whether their decision is feasible, so this problem will be handed to you, hehe, benefits ~, FREE * * Rafting day.
How to solve the problem: first, establish restrictions for the captain and each player
Assuming the captain is a, the other two players are B and C,
When the captain goes back, two players are to be in, that is, to be able to go back, so be satisfied (a V!b) && (a V!c)
When the team member goes back, the captain can't go back, so it's going to be satisfying. (c V B) &&!a, convert it into a (c v!a) && (b v!a)
And then gives the condition that if a member is to be kept, another player must go back, assuming that the players are a and B, then they will meet
(A V!b) && (b v!a)
This will make the map complete.
#include <cstdio>#include <cstring>#include <vector>using namespace STD;#define N 6010 vector<int>G[n];intN, m, top;BOOLMark[n];intS[n];voidInit () { for(inti =0; I <6N i++) g[i].clear ();intX, y, Z; for(inti =0; I < n; i++) {scanf("%d%d%d", &x, &y, &z); g[2* X].push_back (2* y +1); g[2* X].push_back (2* z +1); g[2* Y].push_back (2* x +1); g[2* Z].push_back (2* x +1); } for(inti =0; I < m; i++) {scanf("%d%d", &x, &y); g[2* y +1].push_back (2* x); g[2* x +1].push_back (2* y); }}BOOLDfsintu) {if(mark[u ^1])return false;if(Mark[u])return true; Mark[u] =true; S[++top] = u; for(inti =0; I < g[u].size (); i++)if(!dfs (G[u][i]))return false;return true;}voidSolve () {memset(Mark,0,sizeof(Mark)); for(inti =0; I <6N i + =2) {top =0;if(!dfs (i)) { while(top) mark[s[top--]] =false;if(!dfs (i ^1)) {printf("no\n");return; } } }printf("yes\n");}intMain () { while(scanf("%d%d", &n, &m)! = EOF) {init (); Solve (); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU-1824 let ' s go Home (2-SAT)